« Back to channel list

#ruby - 18 August 2018

« Back 1 day Forward 1 day »
[00:03:52] aeontech: has joined #ruby
[00:06:18] thy0: has joined #ruby
[00:09:01] sameerynho: has joined #ruby
[00:11:37] nicesignal: has joined #ruby
[00:14:52] mroutis: has joined #ruby
[00:17:59] cliluw: has joined #ruby
[00:21:18] yokel: has joined #ruby
[00:23:23] mroutis: has joined #ruby
[00:39:13] orbyt_: has joined #ruby
[00:52:44] cliluw: has joined #ruby
[00:55:46] s2013: has joined #ruby
[01:00:23] j0bk: has joined #ruby
[01:04:20] DarthGandalf: has joined #ruby
[01:16:02] za1b1tsu_: has joined #ruby
[01:38:40] s2013: has joined #ruby
[01:38:57] za1b1tsu_: has joined #ruby
[01:45:19] GodFather: has joined #ruby
[01:50:51] s2013: has joined #ruby
[01:58:21] faitswulff: has joined #ruby
[01:58:59] DTZUZO: has joined #ruby
[02:10:43] jdawgaz: has joined #ruby
[02:11:34] za1b1tsu_: has joined #ruby
[02:26:46] t0xik: has joined #ruby
[02:34:22] booboy: has joined #ruby
[02:37:29] jdawgaz: has joined #ruby
[02:47:29] cadillac_: has joined #ruby
[02:47:32] nightmarer: has joined #ruby
[02:47:32] faitswulff: has joined #ruby
[02:56:29] faitswulff: has joined #ruby
[03:00:31] cadillac_: has joined #ruby
[03:04:52] dviola: has joined #ruby
[03:05:10] sspreitz: has joined #ruby
[03:09:39] za1b1tsu_: has joined #ruby
[03:12:14] faitswulff: has joined #ruby
[03:12:52] CJKinni: has joined #ruby
[03:13:53] braincras: has joined #ruby
[03:15:57] faitswulff: has joined #ruby
[04:00:06] faitswulff: has joined #ruby
[04:17:33] faitswulff: has joined #ruby
[04:22:44] j0bk: has joined #ruby
[04:26:39] patr0clus: has joined #ruby
[04:36:45] patr0clus: has joined #ruby
[04:37:10] faitswulff: has joined #ruby
[04:37:15] za1b1tsu_: has joined #ruby
[04:42:15] kryptoz: has joined #ruby
[04:42:39] Freshnuts: has joined #ruby
[04:43:03] kryptoz: has joined #ruby
[04:43:48] kryptoz: has joined #ruby
[04:45:18] kryptoz: has joined #ruby
[04:46:06] kryptoz: has joined #ruby
[04:47:31] za1b1tsu_: has joined #ruby
[04:59:44] dellavg: has joined #ruby
[05:05:34] kapil___: has joined #ruby
[05:08:44] armyriad: has joined #ruby
[05:15:12] za1b1tsu_: has joined #ruby
[05:17:09] faitswulff: has joined #ruby
[05:31:26] jdawgaz: has joined #ruby
[05:40:52] Furai: has joined #ruby
[06:03:15] segy: has joined #ruby
[06:03:34] graphene: has joined #ruby
[06:11:24] reber: has joined #ruby
[06:14:44] Nicmavr: has joined #ruby
[06:17:30] segy: has joined #ruby
[06:18:33] s2013: has joined #ruby
[06:26:14] tdy: has joined #ruby
[06:33:21] armyriad: has joined #ruby
[06:34:03] SegFaultAX: has joined #ruby
[06:36:58] apeiros: has joined #ruby
[07:05:13] faitswulff: has joined #ruby
[07:12:39] orbyt_: has joined #ruby
[07:15:43] jottr: has joined #ruby
[07:28:01] Dbugger: has joined #ruby
[07:40:09] xuanrui: has joined #ruby
[07:42:24] DarthGandalf: has joined #ruby
[07:52:23] sauvin: has joined #ruby
[08:03:31] snickers: has joined #ruby
[08:05:56] clemens3: has joined #ruby
[08:08:00] za1b1tsu: has joined #ruby
[08:27:28] za1b1tsu_: has joined #ruby
[08:52:53] sameerynho: has joined #ruby
[09:06:34] za1b1tsu: has joined #ruby
[09:12:22] nowhereman_: has joined #ruby
[09:16:10] tristanp: has joined #ruby
[09:21:31] MarcWeber: has joined #ruby
[09:21:41] MarcWeber: Which library to parse date differences like '2 days' ?
[09:27:19] dionysus69: has joined #ruby
[09:28:08] xuanrui: has joined #ruby
[09:51:29] MarcWeber: Which library to parse date differences like '2 days' ?
[09:55:55] ArahaelPi: MarcWeber: I saw your first question, and I still don't know.
[09:56:06] ArahaelPi: MarcWeber: Someone might, but re-posting doesn't help.
[09:57:51] KevinSjoberg: has joined #ruby
[10:00:24] MarcWeber: I did repost because Irssi showed 'joined' after me having send the message, so I was uncertain whether it showed up at al.l
[10:00:52] MarcWeber: I thought its a very common issue, eg PHP has a DateDiff class which gets it done perfectly. I could just wirte a 3line PHP script .. it sucks but works.
[10:02:20] wolfshappen: has joined #ruby
[10:02:30] ArahaelPi: Well, do that, and if someone response, apply the improved version.
[10:12:18] apeiros: MarcWeber: not sure whether chronic also handles duration
[10:12:32] apeiros: it's the only one I remember which handles natural language dates, though
[10:13:19] apeiros: if the format is fixed and simple enough, you can build something on your own relatively easily, though. regex + factor lookup table
[10:17:07] MarcWeber: https://github.com/henrypoydar/chronic_duration Yeah :)
[10:26:44] t0xik: has joined #ruby
[10:27:30] venmx: has joined #ruby
[10:28:48] alex``: What is the more clear between:
[10:29:10] alex``: (in a case / when)
[10:29:28] alex``: until ARGV.empty?
[10:29:49] alex``: parameters[:arguments] << ARGV.shift
[10:30:14] alex``: parameters[:arguments].append(*ARGV)
[10:30:17] alex``: ARGV.clear
[10:31:25] alex``: MarcWeber: Hey o/
[10:32:12] alex``: Looong time not seeing you, hdy?
[10:32:55] kapil___: has joined #ruby
[10:42:15] duderonomy: has joined #ruby
[10:44:14] Alina-malina: has joined #ruby
[10:45:28] jottr: has joined #ruby
[10:47:25] TheBloke: has joined #ruby
[11:06:56] nicesignal: has joined #ruby
[11:15:34] apeiros: alex``: use concat, not append/push with splat
[11:15:58] apeiros: and I'd go with concat+clear. it's faster and rather obvious in intent.
[11:18:40] tristanp: has joined #ruby
[11:22:26] Hobbyboy|BNC: has joined #ruby
[11:30:48] jottr: has joined #ruby
[11:40:38] DTZUZO: has joined #ruby
[11:42:56] faitswulff: has joined #ruby
[11:43:54] Kug3lis: has joined #ruby
[11:46:11] jdawgaz: has joined #ruby
[11:46:32] jottr: has joined #ruby
[11:47:19] dionysus70: has joined #ruby
[11:51:48] d^sh: has joined #ruby
[12:03:19] AJA4350: has joined #ruby
[12:11:53] dionysus69: has joined #ruby
[12:15:21] faitswulff: has joined #ruby
[12:19:31] tristanp: has joined #ruby
[12:37:39] GodFather: has joined #ruby
[12:40:13] pabs: has joined #ruby
[12:42:43] jottr: has joined #ruby
[12:45:55] apparition: has joined #ruby
[13:05:06] savolla: has joined #ruby
[13:11:16] faitswulff: has joined #ruby
[13:21:35] jottr: has joined #ruby
[13:33:36] jtperreault: has joined #ruby
[13:38:29] reber: has joined #ruby
[13:46:11] sticaz: has joined #ruby
[13:52:35] DLSteve: has joined #ruby
[14:07:24] savolla: has joined #ruby
[14:12:35] faitswulff: has joined #ruby
[14:16:54] graphene: has joined #ruby
[14:18:00] mikecmpbll: has joined #ruby
[14:20:15] tristanp: has joined #ruby
[14:23:56] faitswulff: has joined #ruby
[14:29:49] IanMalcolm: has joined #ruby
[14:31:13] xlegoman: has joined #ruby
[14:32:18] Inline: has joined #ruby
[14:37:21] gnufied: has joined #ruby
[14:37:47] alex``: has joined #ruby
[14:38:46] nicesignal: has joined #ruby
[14:41:41] thy0: has joined #ruby
[14:46:51] alex``: How to merge 2 arrays (superpose) like hash?
[14:49:26] alex``: [nil, '%{foo}', "\n"] and ['http://foo.bar', '%{bar}']
[14:49:44] alex``: => ['http://foo.bar', '%{bar}', "\n"]
[14:53:41] cadillac_: has joined #ruby
[14:59:57] al2o3-cr: alex``: a1 | a2 if you want to remove dups
[15:00:52] havenwood: alex``: Or alternatively consider using a Set.
[15:01:35] apeiros: where did the nil go?
[15:01:56] apeiros: or actually - what kind of "merge" is that? based on length?
[15:02:06] savolla: has joined #ruby
[15:02:07] havenwood: The case of the whistling bagpiper and the missing nil.
[15:02:37] danguita: has joined #ruby
[15:02:52] al2o3-cr: it just returns the last array in alex`` way.
[15:03:06] al2o3-cr: hang on no.
[15:03:16] apeiros: >> a = [nil, '%{foo}', "\n"]; b = ['http://foo.bar', '%{bar}']; a[0,b.size] = b; a
[15:03:17] ruby[bot]: apeiros: # => ["http://foo.bar", "%{bar}", "\n"] (https://eval.in/1048755)
[15:04:00] apeiros: that would fit your description alex``. but then again, why do I even bother, didn't even get any kind of response to when I last wrote something.
[15:06:50] kapil___: has joined #ruby
[15:07:31] havenwood: alex``: Is that ^ what you meant when you said "merge 2 arrays (superpose) like hash)"?
[15:08:12] alex``: apeiros: Awesome
[15:08:16] alex``: havenwood: Yep
[15:08:53] alex``: I was going with zip or to_h, but apeiros lot much clear in intent
[15:09:33] laekur: has joined #ruby
[15:09:40] alex``: A.zip(B).map { |pack| pack.compact.last }
[15:10:31] alex``: apeiros: Is there a functional way as simple as your solution?
[15:10:44] graphene: has joined #ruby
[15:10:46] alex``: without relying on modifying a
[15:11:20] apeiros: c = a.size > b.size ? b+a[b.size..-1] : b
[15:11:49] havenwood: alex``: Do you know which Array the `nil`s will be in? One or both? Always up front?
[15:12:10] alex``: Can be both
[15:12:16] Kug3lis: has joined #ruby
[15:12:17] apeiros: shorter but more expensive: c = b + (a[b.size..-1] || [])
[15:12:31] alex``: I write a command-line wrapper around positional arguments
[15:12:40] alex``: to pass to a function
[15:13:03] havenwood: alex``: Can you just share what you're really doing. We can probably give you better suggestions with context.
[15:13:26] apeiros: unless you know that b.size is guaranteed to be <= a.size, then you can just do: c = b + a[b.size..-1]
[15:13:37] danguita: has joined #ruby
[15:13:54] alex``: [nil, 'default-value', 'another-default'].zip(['user-input-one', 'second']).collect { |pack| pack.compact.last }
[15:13:58] dviola: has joined #ruby
[15:13:58] alex``: havenwood: ^
[15:14:32] alex``: apeiros: b would be ARGV or something
[15:14:49] apeiros: alex``: doesn't matter. what matters is knowledge of length
[15:14:57] apeiros: but with ARGV it's a given that oyu don't know.
[15:15:04] apeiros: (never trust user input)
[15:15:21] apeiros: .collect { |pack| pack.compact.last } -> .map { |a,b| b || a }
[15:15:32] havenwood: alex``: Consider option flags?
[15:16:04] alex``: havenwood: What is option flags?
[15:16:26] alex``: apeiros: Thanks again :p
[15:16:34] havenwood: alex``: I meant to show context zoomed out from this line. I was considering doing a writeup on some modern option parsing stuff but only got as far as this little gist: https://gist.github.com/havenwood/02123198a79447543a3ea053e7e592fd
[15:17:43] havenwood: alex``: If you show us what info you're trying to get at, maybe we can suggest a better way to get it from the command line. When you have multiple arguments you want to pass, it can be really nice to pass them coupled by name rather than position.
[15:18:05] havenwood: alex``: Arguments are of course by position. Options are by name.
[15:18:45] alex``: havenwood: where ARGV.options is from ?
[15:19:09] havenwood: alex``: It gets defined when you: require 'optionparser'
[15:19:33] havenwood: alex``: Alternatively you can: OptionParser.new do ...
[15:20:46] havenwood: alex``: https://docs.ruby-lang.org/en/2.5.0/OptionParser.html
[15:21:34] sagax: has joined #ruby
[15:21:44] havenwood: sagax: g'mornin'!
[15:21:57] sagax: it's http://www.ruby2d.com based on SDL?
[15:22:30] jottr: has joined #ruby
[15:23:58] alex``: havenwood: Thanks for you gist
[15:24:31] havenwood: alex``: You're welcome. This reminds me I need to actually write that article.
[15:26:04] alex``: I would like Ruby supporting -flag
[15:26:08] mzo: has joined #ruby
[15:26:12] alex``: instead of --flag
[15:27:20] danguita: has joined #ruby
[15:28:05] havenwood: sagax: Yes, SDL. Here's a talk that gives an overview: http://www.blacktm.com/rubyconf/
[15:29:28] havenwood: sagax: More specifically, it uses: https://github.com/simple2d/simple2d
[15:29:38] havenwood: Which uses SDL.
[15:30:05] havenwood: https://github.com/ruby2d/ruby2d/blob/master/ext/ruby2d/extconf.rb
[15:33:19] alex``: havenwood: Do you mind making yr gist public so I can still see it back from time to time from my Stars?
[15:34:13] alex``: It actually listed in my Stars é_é
[15:34:22] havenwood: alex``: done
[15:34:44] alex``: Thanks :p
[15:35:03] havenwood: alex``: I'll put a link to the article on the gist, when I get around to writing it.
[15:35:49] havenwood: alex``: Ruby stdlib has another option parser called GetoptLong, but I prefer OptionParser: https://docs.ruby-lang.org/en/2.5.0/GetoptLong.html
[15:36:29] havenwood: alex``: Honorable mention to the Slop gem, for a nice interface: https://github.com/leejarvis/slop#slop
[15:38:41] alex``: option.accept is smart
[15:39:26] alex``: havenwood: I get right the prototypes?
[15:40:03] alex``: accept(class, regex-to-pass-string-option, &block-to-transform-string-option)
[15:40:30] za1b1tsu: has joined #ruby
[15:41:01] thejs: has joined #ruby
[15:41:06] alex``: "1" with accept(Integer) would do Integer("1") ?
[15:41:51] alex``: or it requires, accept(Integer, Integer) { |string| string.to_i }
[15:44:01] alex``: havenwood: I was using Thor, but it’s quite too much for the need of the tool I write
[15:47:55] nikivi: has joined #ruby
[15:48:08] nikivi: when you require a relative file
[15:48:28] nikivi: is it possible to use the methods as stated in the file as if they were written in the file you are requiring from?
[15:54:22] LenPayne: has joined #ruby
[15:56:33] nikivi: for example I have method 'def shell()' in file karabiner.rb
[15:57:00] nikivi: and inside config.rb in the same dir that karabiner.rb is, I do 'require_relative 'karabiner.rb''
[15:57:28] nikivi: but then I can't just call the methods from karabiner.rb bare like 'shell()'
[15:57:34] nikivi: is it possible to make that happen?
[15:58:52] havenwood: nikivi: Could you gist the two files? You totally can define a method at top level in a file, require that file, then call the method.
[15:59:16] havenwood: nikivi: I'm not sure why your example isn't working, since what you describes works. It'd be helpful to see your code.
[15:59:21] nikivi: havenwood https://github.com/nikitavoloboev/karabiner-generator
[15:59:32] nikivi: check karabiner.rb which has many methods
[15:59:39] nikivi: and config.rb where I try to call them
[15:59:51] sarna: has joined #ruby
[16:00:26] havenwood: nikivi: You're trying to call them with a different receiver than `main` at top level.
[16:00:34] nikivi: what does that mean?
[16:00:37] havenwood: nikivi: derr
[16:01:36] havenwood: nikivi: You should go ahead and just use Modules.
[16:01:50] havenwood: nikivi: I meant, *err
[16:02:08] nikivi: not too familiar with modules, reading it now
[16:02:15] nikivi: do I have to wrap all my methods as module?
[16:02:16] havenwood: nikivi: Sec, I'll gist and example
[16:02:31] havenwood: nikivi: A module with module_function is a really nice way to namespace.
[16:02:31] nikivi: is there no way to just require the thing and use its methods as if they are in the same file
[16:02:37] havenwood: yes, you can do just that
[16:02:43] sarna: hey, is "The Ruby Programming Language" still relevant? it's from 2008
[16:03:09] havenwood: nikivi: that's why i'm a bit confused why your example isn't working, but this is enough code it's hard to see the minimal reproducible case
[16:03:27] havenwood: sarna: That's still a good book. It's pretty easy to catchup on the last ten years if you understand that book.
[16:03:34] nikivi: config.rb:14:in `main': undefined method `simkeys' for main:Object (NoMethodError)
[16:03:34] nikivi: from config.rb:34:in `<main>'
[16:03:43] nikivi: I get this error trying to call rb on config.rb
[16:04:17] havenwood: nikivi: You define simkeys in that same file, 20 lines later.
[16:04:28] nikivi: I think its due to main
[16:04:32] nikivi: it has to be at the bottom
[16:04:33] havenwood: nikivi: It's a good example of why to use a Module and module_function.
[16:04:47] nikivi: okay I think it works now
[16:04:56] nikivi: I just though I could call main right after def main
[16:05:04] nikivi: and still do def's after main call
[16:05:13] havenwood: nikivi: You can, but you haven't defined the other methods yet.
[16:05:14] sarna: havenwood: thanks
[16:05:30] nikivi: yeah makes sense
[16:05:33] nikivi: just in JS you can do that
[16:05:46] nikivi: declare stuff at end of files and use it earlier
[16:05:48] havenwood: nikivi: Use a module. Sec, I'll gist something for you.
[16:07:13] havenwood: nikivi: https://gist.github.com/havenwood/a5d5100a543f99ad4710580fde1f8d7a
[16:07:55] nikivi: thanks havenwood
[16:08:00] nikivi: but it seems I dont need modules in this case
[16:08:07] nikivi: it seems to work like I want
[16:08:18] havenwood: nikivi: you don't *need* them, but it's a good idea and will save you from issues like what bit you
[16:08:29] havenwood: nikivi: the modules are to make our lives better, not for the machines
[16:08:35] havenwood: nikivi: no prob, any time
[16:09:14] alex``: havenwood: Slop is awesome :)
[16:13:22] dionysus69: has joined #ruby
[16:14:33] havenwood: alex``: Thank ljarvis :-)
[16:19:35] alex``: I like it doesn’t have assumption upon how CLI should be
[16:20:01] alex``: there is no -h --help, etc.
[16:20:12] alex``: or GNU long option forced
[16:23:05] d1rewolf: has joined #ruby
[16:24:08] d1rewolf: all, I'm confused. I would expect: Regexp.new('(\S*)').match("ruby is great") to return three groups (ruby, is, and great). however, it only returns one
[16:24:27] d1rewolf: although testing on rubular, it seems to return three. what am I overlooking?
[16:27:06] jdawgaz: has joined #ruby
[16:28:04] sspreitz: has joined #ruby
[16:30:18] d1rewolf: I'd like to split a string on a pattern, but store what matches the pattern to split as well. So, if I had "x===a".split(/=*/)
[16:30:45] d1rewolf: i'd get "x", "===", and "a". is there a method which does this?
[16:33:02] elomatreb: d1rewolf: match only gets you the first match (if any) by design, you probably want String#scan
[16:36:11] apeiros: >> "x===a".split(/(=*)/)
[16:36:12] ruby[bot]: apeiros: # => ["x", "===", "a"] (https://eval.in/1048765)
[16:36:24] apeiros: d1rewolf: ^
[16:45:58] riclima: has joined #ruby
[16:46:17] IanMalcolm: has joined #ruby
[16:46:41] d1rewolf: apeiros: that works nicely. thx
[16:47:08] leah2: has joined #ruby
[16:47:08] apeiros: note that * as a quantifier will split everywhere, since * allows the empty string as well.
[16:47:15] apeiros: >> "x===abc".split(/(=*)/)
[16:47:21] ruby[bot]: apeiros: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[16:47:23] apeiros: >> "x===abc".split(/(=*)/)
[16:47:24] ruby[bot]: apeiros: # => ["x", "===", "a", "", "b", "", "c"] (https://eval.in/1048767)
[16:47:29] fmcgeough: has joined #ruby
[16:53:02] jdawgaz: has joined #ruby
[16:54:52] Nicmavr: has joined #ruby
[17:06:39] code_zombie: has joined #ruby
[17:11:12] herbmillerjr: has joined #ruby
[17:14:34] thejs: has joined #ruby
[17:17:43] Mikel_: has joined #ruby
[17:19:27] s2013: has joined #ruby
[17:23:16] jottr: has joined #ruby
[17:42:51] galeido: has joined #ruby
[17:44:03] faitswulff: has joined #ruby
[17:54:13] faitswulff: has joined #ruby
[17:55:16] bsamorim: has joined #ruby
[17:59:08] bsamorim: Hi! I'm having trouble installing ruby from source: I followed the instructions from the ruby website. The installation itself succeded but, when I tried running `gem install bundler`, I got the error "Unable to require openssl, install OpenSSL and rebuild Ruby (preferred) or use non-HTTPS sources"
[17:59:13] graphene: has joined #ruby
[17:59:18] bsamorim: Is this a known issue?
[17:59:44] xlegoman: has joined #ruby
[17:59:44] dionysus69: has joined #ruby
[18:00:01] bsamorim: The only oddity about my installation is that I'm running every command as the root user.
[18:00:21] bsamorim: Could this be the cause of the issue?
[18:01:00] bsamorim: I have openssl installed, by the way
[18:08:28] darkhanb: has joined #ruby
[18:08:35] nowhereman_: has joined #ruby
[18:09:22] therealGent: has joined #ruby
[18:11:22] apeiros: bsamorim: I think ruby detects openssl, if it can't find it, it builds without. and then that kind of things happen.
[18:12:00] bsamorim: But I'm installing it before ruby
[18:12:18] apeiros: bsamorim: as far as I'm aware, the best way to build ruby yourself atm is using ruby-install https://github.com/postmodern/ruby-install
[18:12:45] bsamorim: apeiros: thanks a lot for the tip! Is it thinner than rvm?
[18:13:07] apeiros: I think rvm uses that for building ruby (and some other version managers too I think)
[18:13:12] bsamorim: ok, thanks!
[18:20:29] Zaab1t: has joined #ruby
[18:21:48] tristanp: has joined #ruby
[18:30:30] graphene: has joined #ruby
[18:33:57] IanMalcolm: has joined #ruby
[18:37:53] drbrain: has joined #ruby
[18:44:07] faitswulff: has joined #ruby
[18:58:59] riclima: has joined #ruby
[19:02:45] s2013: has joined #ruby
[19:04:44] nowhereman_: has joined #ruby
[19:07:58] johnny56: has joined #ruby
[19:21:51] sarna: has joined #ruby
[19:23:59] Freshnuts: has joined #ruby
[19:24:09] jottr: has joined #ruby
[19:28:48] apeiros: hi riclima, welcome to #ruby
[19:29:03] riclima: I'm a Python developer learning Ruby. I'm trying to get a grip on the Ruby development workflow
[19:29:41] riclima: What's the Ruby equivalent for virtualenv?
[19:29:55] riclima: And/or is it even needed?
[19:30:33] apeiros: as far as I understood what virtualenv does, I'd say rvm or rbenv
[19:30:45] apeiros: those are for ruby versions
[19:30:47] apeiros: bundler for the libraries
[19:31:03] riclima: So from my understanding
[19:31:13] apeiros: i.e. you put a .ruby-version and a Gemfile into your projects and you should be settled.
[19:31:38] riclima: I use bundler to make my gems, and that's the basics?
[19:32:42] apeiros: uh, you can use bundler to create a skeleton for a new gem too, yes
[19:33:18] apeiros: the more common use of it is to enforce specific versions of your dependencies in your projects
[19:33:37] riclima: cool, so bundler also manages dependencies?
[19:34:15] apeiros: in a way. the part it does is enforcing of versions.
[19:34:36] apeiros: I'm not sure how much it does and how much of the work it delegates to rubygems.
[19:35:09] riclima: apeiros: alright, thanks for the help. I'll jump in on the bundler documentation and go from there.
[19:35:11] apeiros: if you make a gem, your Gemfile will usually be mostly empty and just reference the *.gemspec file of your gem.
[19:36:41] elomatreb: One difference to Python might be that bundler and friends don't do the "environment changing" that virtualenv does, you need to prefix commands or use explicit stubs to *force* it to use your specified versions
[19:37:42] apeiros: oh, I think I forget about that because rvm does it. I never prefix `bundle exec`
[19:37:53] apeiros: but good point
[19:38:51] elomatreb: Does it actually apply bundler constraints or is it just a side effect of isolating the installed gems?
[19:39:46] apeiros: I don't use gemsets if you refer to that
[19:40:52] apeiros: ACTION just realized that he's oblivious about the actual mechanics of this
[19:41:00] elomatreb: The fallback behavior from what I remember if you don't prefix bundle exec is to use the latest installed version of a gem
[19:41:01] apeiros: I guess I should fix that one day :D
[19:41:14] apeiros: no, it is run via bundler
[19:42:04] apeiros: otherwise it wouldn't abort if stuff is checked out in the wrong version (git stuff in Gemfile) or not updated/installed.
[19:44:02] elomatreb: In short, Rubygems: Gemfile goes in -> *magic* -> something is executed
[19:50:31] druonysus: has joined #ruby
[19:51:30] t0x: has joined #ruby
[19:56:46] s2013: has joined #ruby
[20:03:52] DTZUZO: has joined #ruby
[20:16:05] s2013: has joined #ruby
[20:17:45] savolla: has joined #ruby
[20:22:40] qolq3: has joined #ruby
[20:22:40] Xiti`: has joined #ruby
[20:22:43] IanMalcolm: has joined #ruby
[20:23:56] Freshnuts: has joined #ruby
[20:27:53] dionysus69: has joined #ruby
[20:34:58] tpendragon: has joined #ruby
[20:43:01] JoshS: has joined #ruby
[20:45:13] IanMalcolm: has joined #ruby
[20:46:59] orbyt_: has joined #ruby
[20:50:42] thy0: has joined #ruby
[20:58:32] dviola: has joined #ruby
[21:04:39] IanMalcolm: has joined #ruby
[21:08:58] s2013: has joined #ruby
[21:15:25] graphene: has joined #ruby
[21:20:08] s2013: has joined #ruby
[21:20:50] RedNifre: has joined #ruby
[21:21:11] apeiros: hallo erfinder
[21:21:20] RedNifre: schnell geblickt!
[21:21:42] apeiros: well, I've seen you a couple of times
[21:21:56] RedNifre: jedenfalls, I was wondering how to sort of do a command line stream script in ruby and how to get a result from it.
[21:22:21] RedNifre: Yeah, I tend to come back here... and to other channels.
[21:22:28] jdawgaz: has joined #ruby
[21:22:44] RedNifre: Anyway, I thought I should try out the old unix tools sed, awk, etc. but I'm not sure it's worth it.
[21:22:54] apeiros: $stdout.sync = true or $stdout.flush after you write
[21:23:48] RedNifre: What I have right now is something that preprocesses a log on the fly, but I need to do some accumulation on it... i guess with ruby I would just pipe to the ruby script which would read from stdin... but since this is sorta infinite, where should I access the accumulated results?
[21:24:42] apeiros: I guess that depends a lot on when you want to have access to accumulated results
[21:24:49] apeiros: and in what form
[21:24:59] jottr: has joined #ruby
[21:25:08] apeiros: and what other information you want to get out of that script
[21:25:19] RedNifre: Say the log looks like "Bob bought 23 green bananas for $10,00 from you." and I already trimmed it down to "Bob 23 green bananas 10.00"... I want to accumulate the money for each purchase per item...
[21:25:48] RedNifre: Oh, wait, maybe I'm just thinking to complex here...
[21:25:56] s2013: has joined #ruby
[21:26:20] RedNifre: I guess I'll just print the whole state of the script on every purchase so I'll always see the latest state when I look at the terminal window.
[21:26:34] RedNifre: That way, there is no "end" result.
[21:26:41] apeiros: that could be a viable approach, yes. printing running totals.
[21:27:03] apeiros: I'm not sure logfiles are the right place for things like this, though.
[21:27:09] apeiros: that's the domain of databases.
[21:27:13] RedNifre: It's just a toy project from a game.
[21:27:22] RedNifre: I thought about this, too, but a database might be overkill.
[21:27:25] apeiros: eh, sqlite is easy to add.
[21:27:32] RedNifre: Sure, but hear me out.
[21:28:06] RedNifre: This is the situation: There is a game, in that game you can open virtual shops and you get chat messages when people buy or sell to your shop. The game logs the chat to a txt file.
[21:28:10] apeiros: there's a big chance other approaches will end up with you having to do a lot more than if you just add a dependency and throw each purchase into a table. summing is trivial from there.
[21:28:43] RedNifre: So my idea is to count what's in my shop when I log in, tell it to the script, and the script reads the chat log to keep the inventory tally updated.
[21:29:05] RedNifre: I considered it and my plan right now is to actually do both.
[21:29:23] RedNifre: however, the nature of the game makes all this very transient.
[21:29:44] RedNifre: i.e. when i log off people will still interact with the shop, which means the inventory count will diverge
[21:30:01] apeiros: you don't get offline messages?
[21:30:04] RedNifre: so what really matters is the inventory count when i log in plus all following chat messages
[21:30:26] RedNifre: it's not a serious professional system, it's just a tiny game that isn't even about shops
[21:31:19] RedNifre: I want to put all the messages in a sqlitedb anyway so i can easily figure out who my most frequent customers are etc. but the immediate goal is more transient.
[21:32:15] RedNifre: ...but that might get a bit too far off topic now... I guess I'll try piping the sed output into a ruby script and have it process it... it's just `gets`, right? For one line of stdin?
[21:32:27] RedNifre: (it's been a while since i last used ruby)
[21:32:41] postmodern: has joined #ruby
[21:32:52] RedNifre: Thanks, I'll see what happens...
[21:32:52] apeiros: Kernel#gets reads from ARGF, which without values in ARGV is just $stdin.gets.
[21:33:04] jdawgaz: has joined #ruby
[21:33:54] apeiros: if you strictly want to read from stdin, you should do $stdin.gets, though. people get confused about "why does ruby say 'no such file `foobar`'?" when they invoke their script as `somescript foobar`.
[21:35:26] graphene: has joined #ruby
[21:36:12] RedNifre: well, i tried `some sed stuff | ruby myscriptrb` and `gets` seems to return empty strings.
[21:36:50] apeiros: that'd mean you got empty lines as input.
[21:37:12] RedNifre: I'm not familiar with the "different" stdin... where in the ruby script do the 5000 lines that get emitted by the sed stuff appear?
[21:38:21] RedNifre: To keep it simple I tried to write an echo command in ruby, just while true do line = gets; puts "got #{line}"; end, nothing too fancy.
[21:38:56] apeiros: stuff piped ends up on $stdin and waits there until you read it
[21:39:12] apeiros: "where in the ruby script" - wherever you read from $stdin.
[21:39:24] apeiros: echo -e "hello\nworld\nthis\nis\nnice." | ruby -e 'while line = $stdin.gets; puts line.upcase; end'
[21:40:09] apeiros: `$stdin.each_line do |line|` will work fine too.
[21:41:34] al2o3-cr: ruby -ne 'puts $_.upcase'
[21:41:51] apeiros: yes, if you want to write short shell oneliners, -n and -p are nice
[21:42:02] apeiros: ruby -e '20.times do |i| puts i; $stdout.flush; sleep 1; end' | ruby -e '$stdin.each_line do |line| puts line.upcase; end' # to test "streaming"
[21:42:33] apeiros: e.g. ^ could just write `| ruby -pe '$_.upcase!'`
[21:43:19] apeiros: pillow time for me. gn8 y'all.
[21:43:32] al2o3-cr: gn apeiros o/
[21:52:12] nadir: has joined #ruby
[21:53:02] DTZUZO: has joined #ruby
[21:59:23] RedNifre: good night!
[21:59:37] RedNifre: and thanks for the help!
[22:01:59] apeiros: has joined #ruby
[22:14:51] apeiros: has joined #ruby
[22:17:24] tdy1: has joined #ruby
[22:19:36] RedNifre: hm, is there a decimal datatype? something for two decimal places?
[22:20:41] elomatreb: RedNifre: What do you mean? There is Float for machine floating point numbers, or Rational if you need precision
[22:21:59] weaksauce: BigDecimal is one option if you need precision
[22:22:13] RedNifre: I need something for decimal numbers with two places, e.g. 10.00
[22:22:50] weaksauce: a general solution to that is to use integers and convert it to two decimal places when needed
[22:23:04] weaksauce: floats are not accurate for money
[22:23:29] elomatreb: Or anything else for that matter :)
[22:23:46] weaksauce: but bigdecimal is
[22:24:37] weaksauce: but i wouldn't use it for that. i would store it as an integer and convert when needed
[22:25:22] za1b1tsu: has joined #ruby
[22:25:37] RedNifre: well, it's just for a game and precision is not that important... if i add 7000 numbers as floats, do I still have 2 decimals precision?
[22:25:51] RedNifre: (i'm pretty much clueless about numerics and accumulated errors...)
[22:26:25] Dark_Arc: has joined #ruby
[22:26:29] weaksauce: there are some values that floats simply cannot handle and round. it really depends.
[22:26:51] weaksauce: https://ruby-doc.org/stdlib-2.5.1/libdoc/bigdecimal/rdoc/BigDecimal.html
[22:27:02] weaksauce: you can see why in that first example
[22:27:09] weaksauce: er second example
[22:27:12] elomatreb: Floats are often the source of bugs or weird behaviors in games, e.g. if you use them for coordinates your points become more spaced out if you go far from the center
[22:27:16] reber: has joined #ruby
[22:27:47] elomatreb: It depends on the numbers
[22:27:52] elomatreb: >> 0.1 + 0.1 + 0.1
[22:27:57] ruby[bot]: elomatreb: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[22:28:05] elomatreb: #=> 0.30000000000000004
[22:28:06] s2013: has joined #ruby
[22:28:57] apeiros: has joined #ruby
[22:29:35] RedNifre: yeah, but if i round to 2 places it's still correct
[22:30:09] weaksauce: if it's just for a game without precision worries you can get away with it
[22:31:26] RedNifre: okay, another thing, how do I do a hash where every entry kinda already exists with value 0.00 ? so I can just do myhash[some_previously_unknown_key] += some_amount ?
[22:31:42] elomatreb: Hash.new(0.0)
[22:31:50] RedNifre: ruby sure is simple :)
[22:32:24] elomatreb: There is a caveat with this if you want to use it with "complicated" objects instead of the "primitives" like numbers, reading the docs of Hash#new is worthwhile
[22:42:07] RedNifre: well, it seems to work... is there a simple list to turn this into an ordered high score list like [["key34", 1000.00], ["key90", 980.00]...] ?
[22:42:37] apeiros: has joined #ruby
[22:42:47] RedNifre: sleepwalking?
[22:43:08] RedNifre: never mind, I'll figure it out...
[22:45:36] fmcgeough: has joined #ruby
[22:45:56] elomatreb: RedNifre: Enumerable#
[22:46:20] elomatreb: ignore that, sorry
[22:46:51] elomatreb: Enumerable#sort_by will help you and was what I meant to say
[22:49:23] RedNifre: well, I did hashmap.to_a.sort { |a, b| a[1] <=> b[1] } instead
[22:50:17] elomatreb: Hashes are ordered and implement Enumerable, so the to_a step is not necesssary fwiw
[22:50:41] alex``: has joined #ruby
[22:52:06] gix: has joined #ruby
[22:52:12] jshjsh: has joined #ruby
[22:54:41] k0mpa: has joined #ruby
[22:54:46] apeiros: has joined #ruby
[22:56:55] sticaz: has joined #ruby
[23:05:48] apeiros: has joined #ruby
[23:11:39] Dark_Arc: has joined #ruby
[23:14:45] moei: has joined #ruby
[23:17:31] apeiros: has joined #ruby
[23:23:20] weaksauce: RedNifre what are you actually trying to accomplish?
[23:23:33] weaksauce: oh nevermind.
[23:25:55] jottr: has joined #ruby
[23:27:32] apeiros: has joined #ruby
[23:32:06] za1b1tsu: has joined #ruby
[23:40:27] RedNifre: weaksauce I finished it, I'm just writing some simple analytics script for a silly game.
[23:40:32] weaksauce: oh i just misread your question
[23:40:57] RedNifre: it's a game where you can build a shop and now I have a high score list of which player bought how much.
[23:42:07] apeiros: has joined #ruby
[23:42:10] weaksauce: glad it's working!
[23:43:18] wolfshappen: has joined #ruby
[23:58:56] apeiros: has joined #ruby