#ruby - 21 May 2018
« Back 1 day Forward 1 day »
[09:12:55] josealobato: Does anybody have any documentation on how to use aruba for testing CLI gems?
[09:13:28] josealobato: I have set it up but I do not know the API and their documentation is terrible (IMO). Of course it is Cucumber use cases.
[09:21:05] Radar: josealobato: https://bundler.io/v1.16/guides/creating_gem.html this guide covers a bit of it.
[09:22:38] josealobato: Thanks Radar, I already read that. I'm trying to go with RSpec instead fo cucumber. I'm looking more about whare the the methods availabe and where and how to set the test files... stuff like that.
[09:33:02] josealobato: In fact I was surprised that their only docs is the cucumber cases. For AC are great but like user documentation is not fantastic.
[12:52:07] warrshrike: is there a queue like thing of fixed size which autoremoves the oldest element when a newer is pushed and size is full?
[16:10:29] yoones: Hi! I'm struggeling with bigdecimal stuff. Ruby keeps rounding values when I don't want it to. I even tried to put my value into a string (works well), but then when I add .to_i it rounds it anyway. How can I prevent this behavior?
[16:18:10] yoones: I basicaly need to do: expect((big_decimal_value * 100).truncate).to eq(csv_value)
[16:18:48] apeiros: we do not care about the csv. extract the value and make the example without needing the csv.
[16:19:37] elomatreb: Alternative possibility: You are sure you convert the CSV value to an appropriate type (as it's probably originally a String)? Ruby does not do implicit typecasts like some other scripting languages
[16:20:43] yoones: elomatreb, Yes, I'm comparing BigDecimal.new(csv_extracted_value, 14) with another BigDecimal value
[16:21:27] yoones: elomatreb, The problem I encounter is that the excel-extracted value has been truncated, and I'm comparing it to a ruby-computed result with more precision
[16:25:11] apeiros: that sounds like you fail - which indicates that your problem does not lie with bigdecimal but your test setup.
[16:25:25] ruby[bot]: elomatreb: # => undefined method `BigDecimal' for main:Object (NoMethodError) ...check link for more (https://eval.in/1007687)
[16:26:30] yoones: elomatreb, If you instanciate it this way, yes. When you get it as the result of a computation, nope
[16:28:08] apeiros: add pry to your Gemfile, or if you don't use gemfiles, install it. require 'pry' in your testcase.
[16:29:26] apeiros: rewrite your testcase from `expect((big_decimal_value * 100).truncate).to eq(csv_value)` to `actual = (big_decimal_value * 100).truncate; p actual_class: actual.class, csv_value_class: csv_value.class, actual: actual, csv: csv_value; expect(actual).to eq(csv_value)`
[16:36:43] yoones: Because big_decimal_value doesn't work, it's pseudo code to ask a question here, my code is a big more complicated
[16:40:07] apeiros: yeah, got better ways to waste my time than somebody who seeks help but doesn't see fit to help those trying to help.
[17:19:45] Eiam: do people here actually depend on the system ruby to do anything? like the default version of ruby that ships with macOS for example
[17:20:19] Eiam: when I was first getting started I used it, then i moved to rvm, later rbenv, and it seems like most developers stop using the system version of interpreters when they move into actually using the language. wondering if I'm the exception
[17:22:52] elomatreb: It really depends on your OS, e.g. on Arch we don't really have outdated rubies
[17:26:31] Eiam: well depending on the OS version means at some point your software will be used with something you didnt' test it with either ?
[17:26:52] Eiam: im wondering aloud if it would matter if OSes stopped shipping with interpreters out of the box
[17:29:09] elomatreb: You have to specify the version in some form anyway, if you don't depend on the OS version you have to either mention it in a readme or include it in some machine-readable form for the people who manually install/build (or use a tool) Ruby
[17:29:50] elomatreb: It would matter, probably not so much in Rubies case but e.g. python and even the shells are essential for OSes
[17:29:52] apeiros: Eiam: I'm on osx and I don't touch system ruby. and I think wouldn't on any box I haven't tailor-made for some purpose.
[17:37:12] Eiam: elomatreb: generally one would bundle their dependencies that are relevant to control
[17:38:59] Eiam: elomatreb: the file system can de-dupe that stuff for you if its that big of a deal
[17:40:01] elomatreb: Not just the pure space. I recently ran out of inodes on a partition because I had a few larger node_modules directories on it
[17:41:16] Eiam: we can find edge cases for any scenario, i don't think thats terribly common or worth hand wringing
[17:42:06] elomatreb: I'm not against ecosystem-specific dependency management, but saying "just bundle it and ship" is unnecessarily wasteful
[17:58:35] havenwood: Eiam: On OSes that have nice up-to-date Ruby packages, I often use those. When you're on a dev machine with multiple legacy apps, some are always going to be on some Ruby enging/version. For that case, it's nice to be able to use system Ruby or one of your choosing.
[17:58:59] havenwood: Eiam: Here's an example of a chruby setup with arch: https://gist.github.com/jhass/8839655bb038e829fba1
[17:59:30] havenwood: Eiam: Since Arch always has a nice recent Ruby, it's worth using. Then you can switch to custom-installed Rubies easily.
[19:29:30] quuxman: so I'm still wondering what I asked on Friday: there must be a better way to write `foo.each do |x| bar_method x end` right?
[19:33:18] quuxman: taht second looks nicer, but only works if bar is in the same scope, and not a parameter
[19:43:05] elomatreb: If you want some other method you have to detach it accordingly, e.g. `foo.map &BazModule.method(:bar)`
[19:47:32] havenwood: quuxman: Matz recently weighed in favorably on the possibility of a new operator that would help.
[19:48:16] elomatreb: quuxman: You can pass around method objects like any other object, but it gets clunky very quickly
[19:48:49] elomatreb: & then calls to_proc on them, which is why e.g. &:stuff works (Symbol#to_proc)
[19:49:24] quuxman: so Ruby strongly discourages functional programming, at least syntactically. It's pretty weird having a dynamic language treat function variables specially, but I suppose it's the ambiguous call syntax that makes the whole mess
[19:50:26] elomatreb: There's nothing special about "function variables", they're regular instances of the Method class
[19:52:10] havenwood: quuxman: Would you consider this syntax to no longer be discouraging functional programming?: Foo.map &BazModule.:bar
[19:54:50] elomatreb: It calls #to_proc on the given object, so the method receives a block it can yield to
[19:55:41] elomatreb: E.g. Symbol#to_proc returns a proc that sends itself (the Symbol) to the yielded object
[19:56:06] quuxman: I read a whole article about the difference between procs and blocks, and I'm not any more clear on them
[19:56:43] elomatreb: It mostly doesn't matter, because very few people are clear on them so they're used interchangeable
[19:57:40] elomatreb: They only difference you do sometimes need to worry about is between procs and lambdas concerning the behavior of returns and breaks
[19:58:00] elomatreb: Yeah, it should obey visibility restrictions by default (I take it regular #method does not?)
[20:15:29] quuxman: ok good to know. So what would leaving out the ampersand do? For example `foo.map(method(:bar))`?
[20:16:47] apeiros: that argument usually being an instance of Method, but really, depends on what self.method(:bar) in that context returns (like all implicit method calls)
[20:20:11] quuxman: on what? Leaving out the ampersand somehow makes an implicit method call on some object?
[20:20:56] elliottcable: I can't, for the life of me, remember how to “open” (in the OCaml sense) a module in Ruby
[20:21:03] havenwood: quuxman: In Ruby a block is a special thing. It often doesn't have an object allocated. You can pass a proc or method object as a block with &.
[20:21:39] apeiros: meaning: foo.map may or may not be Enumerable#map. method(:bar) may or may not be Object#method.
[20:22:30] elliottcable: how can I stop typing `CoolProj::` every three seconds in a consuming file?
[20:22:38] apeiros: but maybe we can change this to something which makes more sense to you: `foo.map(method(:bar))` is the same as `some_arg = method(:bar); foo.map(some_arg)`
[20:22:54] quuxman: So what if I make a def at the top level, like `def foo(x) put x end` and then call it with `foo x`. If everything is a method call, what object is receiving foo?
[20:23:23] apeiros: as said before: methods invoked without an explicit receiver are always sent to self.
[20:24:33] ruby[bot]: havenwood: # => /tmp/execpad-5caf97649c93/source-5caf97649c93:1:in `p': undefined method `inspect' for #<Object:0x40 ...check link for more (https://eval.in/1007801)
[20:27:46] ruby[bot]: havenwood: # => undefined method `const_defined' for Object:Class ...check link for more (https://eval.in/1007804)
[20:32:11] havenwood: banister did a writeup on main: https://banisterfiend.wordpress.com/2010/11/23/what-is-the-ruby-top-level/
[21:23:39] quuxman: in irb, Is there a way to get to a debugger running in the stack frame of the last exception?
[22:10:48] havenwood: quuxman: What about the Hash class is appealing? The methods it responds to? Serialization?