« Back to channel list

#ruby - 12 June 2018

« Back 1 day Forward 1 day »
[00:05:10] shinnya: has joined #ruby
[00:09:33] kmurphy4: has joined #ruby
[00:12:01] nicht: has joined #ruby
[00:16:33] workmad3: has joined #ruby
[00:21:00] sytherax: has joined #ruby
[00:25:19] dviola: has joined #ruby
[00:27:07] BlopMonster: has joined #ruby
[00:29:20] za1b1tsu: has joined #ruby
[00:55:04] rcs: has joined #ruby
[00:58:47] agent_white: has joined #ruby
[01:02:50] tty: has joined #ruby
[01:03:02] sytherax: has joined #ruby
[01:08:18] weird_error: has joined #ruby
[01:10:14] c0ncealed2: has joined #ruby
[01:11:53] sytherax: has joined #ruby
[01:17:42] bga57: has joined #ruby
[01:20:03] chouhoulis: has joined #ruby
[01:22:45] TinkerT: has joined #ruby
[01:25:38] chat_: has joined #ruby
[01:30:37] elomatreb: has joined #ruby
[01:31:05] za1b1tsu: has joined #ruby
[01:44:33] scorpionillumin: has joined #ruby
[01:45:02] scorpionillumin: soooo did anyone answer my question about learning ruby?
[01:52:31] darkhanb: has joined #ruby
[01:54:24] andrewray: has joined #ruby
[01:58:14] jrafanie: has joined #ruby
[01:59:26] karapetyan: has joined #ruby
[02:01:16] agent_white: We regret that the entire planet is temporarily closed.
[02:04:03] za1b1tsu: has joined #ruby
[02:04:16] yokel: has joined #ruby
[02:05:03] ur5us: has joined #ruby
[02:10:18] konsolebox: has joined #ruby
[02:13:08] regedit: has joined #ruby
[02:14:01] gix: has joined #ruby
[02:17:21] workmad3: has joined #ruby
[02:24:21] srruby: has joined #ruby
[02:24:44] srruby: rvm: Should I install it locally? This is on my laptop development machine.
[02:29:23] elomatreb: If you need to version switch, rvm is one option. You don't need it just to get user-local installation
[02:30:24] elomatreb: A combination of https://github.com/postmodern/ruby-install and https://github.com/postmodern/chruby is preferred by a lot of people here though
[02:33:41] srruby: elomatreb: Thanks
[02:46:40] soniya29: has joined #ruby
[02:50:24] chouhoulis: has joined #ruby
[02:50:53] srruby: has joined #ruby
[02:53:02] gigetoo: has joined #ruby
[02:56:10] sleetdrop: has joined #ruby
[02:59:18] gigetoo: has joined #ruby
[03:00:11] cadillac_: has joined #ruby
[03:03:57] nicht: has joined #ruby
[03:04:19] chihhsin: has joined #ruby
[03:09:07] dhollinger: has joined #ruby
[03:09:39] braincrash: has joined #ruby
[03:09:54] gigetoo: has joined #ruby
[03:12:38] gix-: has joined #ruby
[03:17:14] sytherax: has joined #ruby
[03:18:51] bauruine: has joined #ruby
[03:22:27] za1b1tsu: has joined #ruby
[03:32:59] akaiiro: has joined #ruby
[03:36:48] chat: has joined #ruby
[03:44:38] chouhoulis: has joined #ruby
[03:44:38] dreamthese: has joined #ruby
[03:46:34] BlopMonster: has joined #ruby
[03:49:49] SeepingN: has joined #ruby
[03:54:06] chat_: has joined #ruby
[04:01:23] karapetyan: has joined #ruby
[04:08:42] jcarl43: has joined #ruby
[04:14:10] ciscam: has joined #ruby
[04:17:30] TinkerT: has joined #ruby
[04:18:02] workmad3: has joined #ruby
[04:31:14] gigetoo: has joined #ruby
[04:32:41] sytherax: has joined #ruby
[04:35:37] ogres: has joined #ruby
[04:42:18] jud: has joined #ruby
[04:43:45] agent_white: has joined #ruby
[04:53:54] sspreitz: has joined #ruby
[04:54:28] za1b1tsu: has joined #ruby
[04:56:16] chat: has joined #ruby
[05:01:16] cadillac_: has joined #ruby
[05:03:17] karapetyan: has joined #ruby
[05:09:35] ur5us: has joined #ruby
[05:10:45] theRoUS: has joined #ruby
[05:13:07] anisha: has joined #ruby
[05:18:48] bbobb: has joined #ruby
[05:23:05] sspreitz: has joined #ruby
[05:24:47] za1b1tsu: has joined #ruby
[05:28:47] reber: has joined #ruby
[05:29:45] ciscam: has joined #ruby
[05:30:38] gigetoo: has joined #ruby
[05:32:05] dionysus69: has joined #ruby
[05:33:40] RougeR: has joined #ruby
[05:36:36] gigetoo: has joined #ruby
[05:40:21] byte00: has joined #ruby
[05:52:47] conta: has joined #ruby
[05:57:53] aupadhye: has joined #ruby
[06:02:21] sauvin: has joined #ruby
[06:03:02] syndikate: Is there an opposite of Hash#slice in ruby? Like I can provide a key which I don't want and display the hash with rest of the key and values?
[06:05:12] elomatreb: Rails has that (#except I think?), but I don't think there is in vanilla.
[06:05:43] syndikate: Okay, I doubt if it works on hashes, let me check
[06:06:04] za1b1tsu_: has joined #ruby
[06:06:24] dminuoso: syndikate: You can always to_a, reject/select, to_h
[06:06:50] dminuoso: >> h = { a: 1, b: 2, c: 3 }; h.reject { |(k, v)| k == :a }.to_h
[06:06:51] ruby[bot]: dminuoso: # => {:b=>2, :c=>3} (https://eval.in/1019276)
[06:07:48] syndikate: Okay, so there is no ready method which would accept just a key I would have to provide a block
[06:08:22] dminuoso: No and I dont think it'd be a wise thing to have.
[06:08:44] elomatreb: >> h = { a: 1, b: 2, c: 3, d: 4 }; v.values_at *(h.keys - [:b, :c]) # hmm
[06:08:45] ruby[bot]: elomatreb: # => undefined local variable or method `v' for main:Object (NameError) ...check link for more (https://eval.in/1019277)
[06:08:52] elomatreb: >> h = { a: 1, b: 2, c: 3, d: 4 }; h.values_at *(h.keys - [:b, :c]) # hmm
[06:08:53] ruby[bot]: elomatreb: # => [1, 4] (https://eval.in/1019278)
[06:09:00] elomatreb: Oh wait nevermind
[06:09:06] dminuoso: syndikate: For the simple reason that I just showed you. The code to do what you want is highly trivial, and it's not common.
[06:09:34] dminuoso: To have methods to do uncommon and trivial things just makes you look for "DSL" more instead of solving problems.
[06:09:38] dminuoso: It's the Rails disease.
[06:09:40] braindead_: has joined #ruby
[06:09:55] biberu: has joined #ruby
[06:09:57] elomatreb: Ruby already has a very expansive standard library, if it added every function that "could be useful" it'd grow huge
[06:10:13] syndikate: Makes sense. Guess I have that rails disease
[06:10:39] elomatreb: You can pull in ActiveSupport (the library extension part of Rails) independently of Rails, if you *really* want
[06:10:57] syndikate: In fact #except works as well like elomatreb said. But, good to know these. Thanks elomatreb dminuoso
[06:11:07] syndikate: I already have it but I wanted to know about ruby as well :)
[06:11:18] dminuoso: syndikate: You just make it harder for Rubyists to read your code.
[06:11:42] syndikate: dminuoso, if I use rails methods?
[06:12:06] dminuoso: syndikate: Rails is not standard, their implementations are *weird* with a lot of guess magic, frequently slow.
[06:12:10] elomatreb: This is getting into opinion territory, personally I like using this specific one since it's definitely quicker to get what it does than the reject/to_h combo
[06:12:25] dminuoso: If I get to see code using .except Im gonna purge that in favour of h.reject { |(k, v)| k == :a }.to_h
[06:12:27] sytherax: has joined #ruby
[06:13:01] dminuoso: elomatreb: Are you sure about that?
[06:13:05] dminuoso: elomatreb: Will except be indifferent wrt to strings and symbols?
[06:13:16] dminuoso: ^- this amongst other problematic behaviors is why I avoid ActiveSupport.
[06:13:19] syndikate: I faced that issue
[06:13:28] syndikate: And was irked
[06:13:40] elomatreb: Arguably in that case the actual problem is that you're mixing strings and symbols, but I get what you mean
[06:13:41] syndikate: I kept providing keys for a while and was wondering why the method is not working
[06:13:51] syndikate: Keys == symbols
[06:13:55] rippa: has joined #ruby
[06:18:46] workmad3: has joined #ruby
[06:18:53] Scriptonaut: has left #ruby: ()
[06:20:22] clemens3_: has joined #ruby
[06:22:37] clemens3: has joined #ruby
[06:22:54] Zladivliba: has joined #ruby
[06:23:03] Zladivliba: hello everyone
[06:30:58] konsolebox: has joined #ruby
[06:34:44] bobdobbs: has joined #ruby
[06:41:50] andikr: has joined #ruby
[06:43:00] srruby: has joined #ruby
[06:48:42] amar: has joined #ruby
[06:51:15] dr3wo: has joined #ruby
[06:57:51] Zaab1t: has joined #ruby
[07:04:47] karapetyan: has joined #ruby
[07:07:58] Furai: has joined #ruby
[07:11:33] clemens3: has joined #ruby
[07:14:12] drale2k_: has joined #ruby
[07:15:51] bauruine: has joined #ruby
[07:17:06] TomyWork: has joined #ruby
[07:18:38] yohji: has joined #ruby
[07:22:47] ellcs: has joined #ruby
[07:24:19] armando: has joined #ruby
[07:29:57] schleppel: has joined #ruby
[07:30:02] sysvalve: has joined #ruby
[07:33:03] Beams: has joined #ruby
[07:38:49] vondruch: has joined #ruby
[07:40:30] armando: has joined #ruby
[07:40:51] Megamos: has joined #ruby
[07:42:06] sytherax: has joined #ruby
[07:43:26] vondruch: has joined #ruby
[07:50:37] t0xik: has joined #ruby
[07:53:17] sphenxes: has joined #ruby
[07:55:02] sytherax: has joined #ruby
[07:57:05] nadir: has joined #ruby
[07:58:35] rfv: has joined #ruby
[08:03:00] mikecmpbll: has joined #ruby
[08:06:11] ellcs: has joined #ruby
[08:06:27] jottr: has joined #ruby
[08:08:15] burgestrand: has joined #ruby
[08:12:59] amar: has joined #ruby
[08:15:05] amar: has joined #ruby
[08:19:31] workmad3: has joined #ruby
[08:20:28] amar: has joined #ruby
[08:21:08] dr3wo: has joined #ruby
[08:24:34] tomeaton17: has joined #ruby
[08:26:06] amar: has joined #ruby
[08:31:25] sytherax: has joined #ruby
[08:35:36] spooky_d: has joined #ruby
[08:39:23] spooky_d: has left #ruby: ()
[08:41:08] ramfjord: has joined #ruby
[08:42:59] meinside: has joined #ruby
[08:47:59] vaios: has joined #ruby
[08:48:06] vaios: has left #ruby: ()
[08:49:37] workmad3: has joined #ruby
[08:53:08] vondruch: has joined #ruby
[08:54:39] kapil___: has joined #ruby
[08:56:39] ramfjord: has joined #ruby
[09:02:19] mikecmpbll: has joined #ruby
[09:03:11] Bish: >> h = {};h[:t] = *[1]
[09:03:12] ruby[bot]: Bish: # => [1] (https://eval.in/1019343)
[09:03:21] Bish: why wouldn't it be 1?
[09:03:43] Bish: i mean.. i h[k] = *x not equivalent with h.[]=(*args)
[09:06:26] karapetyan: has joined #ruby
[09:07:46] za1b1tsu: has joined #ruby
[09:08:41] Bish: >> h = {};h[:f] = *[1];h[:s].[]=(:s,*[1]);h
[09:08:42] ruby[bot]: Bish: # => undefined method `[]=' for nil:NilClass (NoMethodError) ...check link for more (https://eval.in/1019344)
[09:09:11] Bish: >> h = {};h[:f] = *[1];h[]=(:s,*[1]);h
[09:09:12] ruby[bot]: Bish: # => /tmp/execpad-1548a7909d18/source-1548a7909d18:2: syntax error, unexpected ',', expecting ')' ...check link for more (https://eval.in/1019345)
[09:09:20] dminuoso: asm>> h = {};h[:t] = *[1]
[09:09:21] ruby[bot]: dminuoso: I have disassembled your code, the result is at https://eval.in/1019346
[09:09:22] Bish: >> h = {};h[:f] = *[1];h.[]=(:s,*[1]);h
[09:09:23] ruby[bot]: Bish: # => {:f=>[1], :s=>1} (https://eval.in/1019347)
[09:09:32] Bish: asm>> h = {};h[:f] = *[1];h.[]=(:s,*[1]);h
[09:09:40] balo: has joined #ruby
[09:09:57] dminuoso: Bish: for the same reason that:
[09:10:09] dminuoso: a = *[1] # gives you [1] in a
[09:10:20] tekk: has joined #ruby
[09:10:41] Bish: but the splat doesnt do squid
[09:10:43] dminuoso: The main problem is that you are using this `*` thing without really knowing what it does.
[09:10:56] ur5us: has joined #ruby
[09:10:59] dminuoso: And the reason you don't know, is because we don't have a real specification that tells you the semantics of it.
[09:10:59] Bish: well in that case, it doesnt do anything
[09:11:07] dminuoso: The ISO standard that does exist is behind a paywall.
[09:11:27] dminuoso: The real question should be: Why do we have these completely magical things in Ruby that are not documented anywher.
[09:11:29] Bish: well in any case i expected []=(k,v) to be equivalent with [k]=v
[09:11:42] jottr: has joined #ruby
[09:11:45] Bish: no matter what i understand wrong about ruby
[09:11:53] apeiros_: Bish: because of auto-unsplat
[09:11:55] dminuoso: 11:11 dminuoso | The real question should be: Why do we have these completely magical things in Ruby that are not documented anywher.
[09:11:58] apeiros_: a,* = *[1]; a
[09:12:00] apeiros_: >> a,* = *[1]; a
[09:12:01] ruby[bot]: apeiros_: # => 1 (https://eval.in/1019348)
[09:12:13] apeiros: >> a = 1,2,3; a
[09:12:15] dminuoso: Bish: Ruby is learned by means of anecdotes and stories.
[09:12:16] ruby[bot]: apeiros: # => [1, 2, 3] (https://eval.in/1019349)
[09:12:24] NL3limin4t0r: has joined #ruby
[09:12:29] apeiros: IMO one of the unfavorable choices.
[09:12:42] apeiros: I'd prefer explicit splat/unsplat rules
[09:13:03] Bish: so.. can i splat a single element array into an assignment?
[09:13:08] Bish: how would explizit look
[09:13:23] dminuoso: Unlike basically *every other language on this planet* Ruby has a lot of magic undocumented features.
[09:13:34] apeiros: Bish: as I showed, by not having a single left-hand side
[09:13:36] dminuoso: You learn them by randomly asking on reddit, SO or IRC.
[09:13:39] dminuoso: Or digging into the source code
[09:13:41] Bish: thats what makes ig good
[09:13:49] Bish: mysterious
[09:13:52] Bish: im kidding.
[09:13:56] apeiros: one way of "not having a single lhs" is by using `,*`
[09:14:11] apeiros: >> a,* = *[1]; a # <-- this
[09:14:12] ruby[bot]: apeiros: # => 1 (https://eval.in/1019350)
[09:14:14] dminuoso: And yes. Id *love* to be able to point people to an official reference documentation that explained the meaning and behavior of things
[09:14:21] Bish: apeiros: well, and how does it wok?
[09:14:31] Bish: what do i actually say that, and how is that equivalent with
[09:14:35] Bish: h.[]=(k,v)
[09:14:40] ellcs: has joined #ruby
[09:14:51] pragmatism: has joined #ruby
[09:14:57] apeiros: Bish: essentially if ruby detects a single lhs and a splat on rhs, it will "unsplat", i.e. turn rhs into an array
[09:15:06] apeiros: by forcing a splat on lhs, that's avoided
[09:15:10] Bish: ah i get it
[09:15:15] apeiros: lhs/rhs = left hand / right hand side
[09:15:21] Megamos: has joined #ruby
[09:15:29] apeiros: i.e. left and right of the assignment operator
[09:15:30] Bish: and why does it do that?
[09:15:39] apeiros: *that* is an entirely different question. ask matz :)
[09:15:47] apeiros: I *assume* it was thought to be convenient.
[09:15:56] apeiros: as said, it goes counter to my intuition and preference.
[09:15:59] Bish: what datatypes are splated by default?
[09:16:06] Bish: i mean.. you will have to do that explicitly..
[09:16:19] Bish: and then it unsplats, eh?
[09:16:22] Bish: i don't follow
[09:16:29] ectos: has joined #ruby
[09:16:41] apeiros: sadly it does autosplat. see:
[09:16:49] apeiros: >> a,b,c = [1,2,3]; c
[09:16:50] ruby[bot]: apeiros: # => 3 (https://eval.in/1019353)
[09:16:54] gil_: has joined #ruby
[09:16:54] gil_: has joined #ruby
[09:17:00] apeiros: and I *think* it does that with everything that responds to to_ary
[09:17:30] apeiros: >> class Foo; def to_ary; [1,2,3]; end; end; a,b,c = Foo.new; c
[09:17:31] ruby[bot]: apeiros: # => 3 (https://eval.in/1019354)
[09:17:43] apeiros: ^ would indicate my recollection is correct
[09:18:07] Bish: >> a,b,c = d = [1,2,3,4];[d,a,b,c]
[09:18:08] ruby[bot]: Bish: # => [[1, 2, 3, 4], 1, 2, 3] (https://eval.in/1019355)
[09:18:08] apeiros: >> class Foo; end; a,b,c = Foo.new; c # counter-test
[09:18:09] ruby[bot]: apeiros: # => nil (https://eval.in/1019356)
[09:18:10] dminuoso: Bish: actually: https://www.ipa.go.jp/files/000011432.pdf
[09:18:13] Bish: ohshit, lol
[09:18:25] dminuoso: Bish: It's defined right there under 11.4.2.4 Multiple assignments
[09:18:37] dminuoso: 11.5.2.2.4 The case expression
[09:18:52] dminuoso: and: 11.3.2 Method arguments
[09:25:19] Es0teric: has joined #ruby
[09:26:07] hfp_work: has joined #ruby
[09:34:38] sytherax: has joined #ruby
[09:35:41] Bish: well but thats more ugly then just calling .first on the array
[09:37:05] jottr: has joined #ruby
[09:39:55] dionysus69: this is so weird!
[09:39:57] dionysus69: => 0.27999999999999997
[09:40:14] dminuoso: What is weird about that?
[09:40:18] Bish: welcome to IEEE754
[09:40:42] dionysus69: to get correct answer I should do to_d.to_f???
[09:40:47] Haradani: has joined #ruby
[09:40:51] dionysus69: that way I get 0.28
[09:40:56] Bish: i have a better one for yah
[09:40:59] Bish: >> 0.1+0.2
[09:41:00] ruby[bot]: Bish: # => 0.30000000000000004 (https://eval.in/1019465)
[09:41:08] dminuoso: dionysus69: Use Rational.
[09:41:18] dminuoso: Dont use floating point numbers if you dont understand the implications.
[09:41:27] dionysus69: hmm ok let me look it up
[09:41:32] Bish: or if you care about the implications
[09:42:26] dionysus69: what do you mean use rational? dminuoso
[09:42:29] apeiros: Rational or BigDecimal are the choices.
[09:42:34] Bish: dionysus69: if you find a better way to express floating point numbers with a finite and fixed number of bits, tell me
[09:42:38] apeiros: >> 1/2r.class
[09:42:39] ruby[bot]: apeiros: # => Class can't be coerced into Fixnum (TypeError) ...check link for more (https://eval.in/1019466)
[09:42:47] apeiros: >> (1/2r).class
[09:42:48] ruby[bot]: apeiros: # => Rational (https://eval.in/1019467)
[09:43:17] dionysus69: need to get float as a result so to_d.to_f sounds simplest so far
[09:43:24] conta: has joined #ruby
[09:43:39] dminuoso: dionysus69: That sounds absolutely terribly wrong.
[09:43:57] apeiros: "need to get float as a result" - why?
[09:44:10] dionysus69: then what is your solution for let's say 0.48 - 0.2
[09:44:12] dminuoso: I cant fathom what you are trying to do, but Im convinced you are doing this wrong.
[09:44:21] dionysus69: I need to pass it to a service, it accepts only floats
[09:44:30] dminuoso: So whats wrong with 0.27999999999999997
[09:44:43] dionysus69: needs to be precise :D
[09:44:52] apeiros: >> require 'bigdecimal'; BigDecimal("0.48") - BigDecimal("0.2") # dionysus69
[09:44:53] dionysus69: that is just wrong lol
[09:45:04] ruby[bot]: apeiros: # => #<BigDecimal:40b8172c,'0.28E0',9(18)> (https://eval.in/1019469)
[09:45:14] dionysus69: that returns e0 notation
[09:45:23] apeiros: dionysus69: you are passing a binary float representation to the service?
[09:45:28] dionysus69: then I would have to_f it anyway :D
[09:45:30] apeiros: I very seriously doubt that
[09:45:46] dionysus69: imagine cents in cents
[09:45:50] apeiros: you almost certainly pass a *string* representation of a decimal to the service, and NOT a float.
[09:45:53] dminuoso: 11:44 dionysus69 | needs to be precise :D
[09:45:58] dminuoso: You do not seem to understand what you are saying
[09:45:58] dionysus69: you cant pass 0.2888888 cents for 29 cents right?
[09:46:06] dminuoso: Do. Not. Use. FP. For. Money.
[09:46:22] apeiros: there's like tons of material about that on the net.
[09:46:27] dionysus69: I mean, I am doing all of the things in bigdecimal
[09:46:29] Bish: what about bitcoins
[09:46:35] Bish: they use floats for money
[09:46:35] dminuoso: dionysus69: Do. Not. Use. FP. For. Money.
[09:46:39] dionysus69: but at the end, I need to transform it into floaT :D :D
[09:46:52] dionysus69: Bish: exactly
[09:46:54] dminuoso: dionysus69: do your calculations in Rational.
[09:46:56] apeiros: dionysus69: again - you are almost certainly NOT passing a binary float to the service
[09:46:57] Bish: dionysus69: then people will lose money :D :D
[09:47:02] apeiros: dionysus69: so NO, you do NOT need a float.
[09:47:09] apeiros: "1.23" is NOT a float. it's a string.
[09:47:22] dionysus69: yea, I meant string float
[09:47:25] dionysus69: not a binary float
[09:47:29] apeiros: yeah, stop using that term
[09:47:33] dminuoso: dionysus69: if you want to calculate with money, use rational, integers or a money library.
[09:47:34] Bish: dionysus69: no.. bitcoins are represented by bits already, there is no way to have a "wrong" result with them
[09:47:36] apeiros: that's not a float. period.
[09:47:41] dionysus69: ok :D so how do I get string float from a BigDecimal("0.48") - BigDecimal("0.2")
[09:47:47] Bish: are you talking about cryptocurrency?
[09:48:10] apeiros: dionysus69: you don't. you get decimal string from it using to_s("F")
[09:48:18] dminuoso: dionysus69: you subtract *centwise*
[09:48:26] apeiros: >> require 'bigdecimal'; (BigDecimal("0.48") - BigDecimal("0.2")).to_s("F")
[09:48:26] dminuoso: dionysus69: turn the whole thing into *cents*, then use Integer.
[09:48:27] ruby[bot]: apeiros: # => "0.28" (https://eval.in/1019473)
[09:48:32] apeiros: ^ dionysus69
[09:48:43] dionysus69: ok great string conversion gave me the correct answer
[09:48:54] dminuoso: dionysus69: You need to use *INTEGER*
[09:48:59] spooky_d: has joined #ruby
[09:49:00] apeiros: dminuoso: they'll just divide by 100 getting a float again and convert that to a string. so you're just pushing the issue around ;-p
[09:49:04] dionysus69: for what dminuoso?
[09:49:10] dminuoso: apeiros: not really.
[09:49:15] spooky_d: How can I build a proper binding for an eval that will call require_relative?
[09:49:16] dminuoso: apeiros: it becomes a string > int parsing issue.
[09:49:52] apeiros: dminuoso: if the service wants a string with a dot in it, it's an int -> decimal string conversion issue
[09:50:14] apeiros: and I'm pretty sure dionysus69's solution to that would be what I said ;-)
[09:50:28] dminuoso: apeiros: yes but then you can just divmod it.
[09:50:35] dminuoso: >> 413.divmod(100)
[09:50:36] ruby[bot]: dminuoso: # => [4, 13] (https://eval.in/1019480)
[09:50:40] dminuoso: voila. euros and cents.
[09:50:42] apeiros: dminuoso: sure, you and I would :D
[09:50:52] Bish: is there a counter part to empty?
[09:51:19] apeiros: spooky_d: provide the eval a filename
[09:51:43] apeiros: spooky_d: also you commit 2 sinds - you're using eval and require_relative. you should go into the corner and think about that for a while :-p
[09:51:50] dminuoso: dionysus69: please tell me the name of the website you are working for
[09:51:53] dminuoso: So I can put it on my avoidance list.
[09:52:40] dionysus69: I am doing this in development mode lol, I am not pushing this stuff to production ^.^
[09:52:55] cdunklau: dionysus69: that's what they all say
[09:52:57] spooky_d: apeiros: tell me how not to sin. I have a ruby script with require_relative, and I want to invoke it from C.
[09:53:06] Bish: BadFloatingCoin ICO
[09:53:24] cdunklau: i'm pretty sure bitcoin uses ints
[09:53:38] Bish: cdunklau: .. well bitcoin itself as a finitie precision..
[09:53:41] Bish: lowest being satoshi..
[09:53:45] Bish: so it's kinda equivalent
[09:53:50] spooky_d: And I want to invoke it in such a way that it won't pollute stuff with global constants.
[09:53:51] apeiros: spooky_d: let your executable set up $LOAD_PATH and use require instead of require_relative
[09:54:16] apeiros: spooky_d: as for invoke ruby from C - well, I guess that will indeed be some form of eval, so you're absolved of that sin ;-)
[09:54:18] spooky_d: I don't really choose if require_relative is used or not, and I know for certain it is used.
[09:54:19] cdunklau: Bish: right, so the right way of doing bitcoins is to do it all in ints
[09:54:30] apeiros: (just like `ruby some_script.rb` is essentially a glorified eval)
[09:54:34] Bish: well.. or just floats with the amount of bits in btc..
[09:54:45] cdunklau: and then just divide by 1e8
[09:54:45] Bish: because it's not possible to add/substract 2 valid values from each other
[09:54:47] Bish: and get problems
[09:55:22] Bish: but yeah.. whoever does not do money with integers, is crazy
[09:55:37] dminuoso: Bish: Ideally you would not do it with integers either.
[09:55:53] Bish: sure.. but it doesn't matter, actually since being equivalent at some level
[09:56:04] Bish: but since its easier to model.. yeah int
[09:56:37] spooky_d: Thank you :)
[09:57:06] dminuoso: dionysus69: floating point numbers are represented as `significant * (base ^ exponent)`
[09:57:30] dminuoso: dionysus69: with `base` usually being 2 (IEEE 754 also allows for base being 10, but for efficiency reasons that's usually not implemented)
[09:57:58] apeiros: it'd be really nice if we had hardware base10 floats :-/
[09:58:16] dminuoso: IEEE754 then defines multiple precision levels. With single precision the exponent has exactly 8 bits and the significand has exactly 23 bits.
[09:58:44] dminuoso: dionysus69: ^- with this it should be obvious that IEEE754 is only able to represent certain discrete numbers.
[09:59:50] Bish: apeiros: how does the precision matter? i mean even if you had magicially base10 digits
[09:59:53] Bish: if you don't have endless of them
[09:59:56] Bish: it doesn't matter
[10:00:21] cdunklau: we should just use trinary floats so 1/3 would be exactly representable!
[10:00:22] Bish: how does the base matter*
[10:00:51] dionysus69: Those things are little vague to me but I get the essence :)
[10:01:28] dminuoso: dionysus69: THe specification then talks how arithmatic works. If you look close you will note that FP arithmetic breaks pretty much most mathematic laws you'd expect.
[10:01:51] dminuoso: For example in IEEE754 it is not guaranteed that `a == a # => true`
[10:02:02] dionysus69: btw rubocop gave me warning, BigDecimal.new is deprecated, seems like BigDecimal("0.1") does the job
[10:02:15] dminuoso: dionysus69: Seriously. Just use integers, its not hard.
[10:02:24] Bish: god, i hate .infinite? and .nan?
[10:03:08] dionysus69: I actually do have an integer, but then I divide it by a million to get needed precision with decimal places
[10:03:37] dminuoso: apeiros ^- tell me you read this
[10:03:57] dionysus69: service returns integer as balance, but I need decimals in my app
[10:04:13] dminuoso: dionysus69: what do you mean "I need decimals in my app"
[10:04:32] dminuoso: dionysus69: "1,50" is a *representation* form, not a storage form.
[10:04:44] cdunklau: dionysus69: if you need to display them with decimal points, just do the division right before you format it for display
[10:04:45] tbuehlmann: Money.new(cents).to_s ding ding ding
[10:04:46] dionysus69: so I have to convert it to decimals and then return back to integers
[10:05:04] dminuoso: dionysus69: dont convert to decimals *at all*
[10:05:07] dionysus69: I need to show decimals to users, like you wouldn't want to show cents to the users
[10:05:11] dminuoso: dionysus69: You have Integer and some string representation.
[10:05:30] dionysus69: hmm ok I get what you are saying, I actually tried that
[10:06:02] dionysus69: but that meant modifying methods for this particular currency
[10:06:07] dionysus69: others dont use integers
[10:06:24] dminuoso: >> def pretty_money(cents); e, c = cents.divmod(100); sprintf("%d,%02d€", e, c); end; pretty_money(10)
[10:06:25] ruby[bot]: dminuoso: # => "0,10€" (https://eval.in/1019486)
[10:06:26] dminuoso: >> def pretty_money(cents); e, c = cents.divmod(100); sprintf("%d,%02d€", e, c); end; pretty_money(173)
[10:06:27] ruby[bot]: dminuoso: # => "1,73€" (https://eval.in/1019487)
[10:06:34] dionysus69: others like bitcoin use 8 precision decimals, string decimals at least
[10:06:44] venmx: has joined #ruby
[10:08:50] dminuoso: dionysus69: a "decimal" is just a fancy word for rational./
[10:09:05] dminuoso: When we write: 0.01 we actually mean 1/100
[10:09:28] dminuoso: The main problem is that programming languages have made a habit of considering 0.01 as floating point, which is something we dont ever think in.
[10:09:33] karapetyan: has joined #ruby
[10:09:50] Bish: be rational!
[10:09:59] dminuoso: dionysus69: Just use Integer. you can use the method I just showed you to pretty it. Or follow tbuehlmann's advice and use Money.
[10:10:09] dionysus69: yes rationals make sense, but user inputs a floating point string for transferable amount
[10:10:16] dminuoso: No they dont.
[10:10:19] dminuoso: They input *A STRING*
[10:10:26] dionysus69: ok ok I get it :D
[10:10:33] Bish: so it's a float?
[10:11:14] dionysus69: thanks dminuoso :D you are nice :P
[10:11:38] dminuoso: So yes. You will probably want an inverse of pretty_print, one that *PARSES* some user input into cents or fails.
[10:12:06] dminuoso: A naive implementation might be
[10:12:18] dionysus69: yea I'll figure something out :)
[10:12:29] Bish: >> user_input = "1.1"; eval "#{user_input}r"
[10:12:29] alex``: has joined #ruby
[10:12:30] ruby[bot]: Bish: # => (11/10) (https://eval.in/1019489)
[10:12:36] Bish: :D no im kidding dont do that
[10:13:19] spooky_d: class C1; X=100; def p; eval("puts X; require_relative 'test'", binding, '/home/spooky/x.cfg'); end; end;
[10:13:33] spooky_d: if test.rb contains a puts X
[10:13:40] spooky_d: it complains about X being not defined.
[10:14:07] spooky_d: Does this make sense?
[10:14:27] spooky_d: Anyway, here's what I need, really, because I'm probably asking the wrong question
[10:14:48] spooky_d: I want to run a ruby script (preferably with load)
[10:15:06] venmx: has joined #ruby
[10:15:08] spooky_d: and clean the global_constants of all the constants it defines.
[10:15:17] dminuoso: dionysus69: Or you could rely on the Money gem. It should have what you want built in already - and its not bad.
[10:15:21] spooky_d: Because then I get the output corrupted with warnings.
[10:15:34] dminuoso: dionysus69: But it's not a hard problem. You should use it as practice perhaps
[10:15:34] spooky_d: And I don't want to disable those warnings, but I need the output clean.
[10:15:40] dionysus69: dminuoso: nah, I prefer doing it manually, I ll change methods to deal with integers I guess, it's safest
[10:15:56] dionysus69: other currencies so far all of them had 8 precision floating strings so all was good
[10:16:14] dminuoso: dionysus69: what is a "8 precision floating string"
[10:16:18] dminuoso: what does that even mean?
[10:16:30] Bish: they have 8 base10 digits
[10:16:32] dionysus69: 0.00000001 that is one satoshi in bitcoin world for example
[10:17:03] dionysus69: haha I know i came up with that name on the fly :D
[10:17:12] dminuoso: stop using the word floating here.
[10:17:30] Bish: and 1^-8 is 1
[10:17:45] dionysus69: 1*10 ... ok ok
[10:18:11] dminuoso: the reason why floating point is called floating point, is because the *point* can float from left to right during arithmetic.
[10:18:23] dminuoso: or in both directions rather
[10:19:17] dionysus69: yea I know, I've heard of the floating point processor, inside the cpu :)
[10:20:51] dminuoso: dionysus69: "102301.231" is just a decimal representation of a *fraction*
[10:21:11] dminuoso: that is, it's a way to express the division: 102301231 / 1000
[10:21:30] dionysus69: yea makes sense :)
[10:22:15] dminuoso: dionysus69: now bitcoin can be thought of as consisting of just μBTC.
[10:23:16] dminuoso: or.. no I think msat is the smallest?
[10:23:55] dionysus69: yea but the btc node itself receives and returns values based on btc not μBTC
[10:24:23] dminuoso: dionysus69: That's just a representation form.
[10:24:27] dionysus69: oh that is 0.000001 not satoshi though
[10:24:30] dminuoso: dionysus69: In reality you still transmit millisatoshis.
[10:24:35] Haradani: has joined #ruby
[10:24:42] dionysus69: well, yea I guess
[10:24:55] dminuoso: it's similar how the information 2,45EUR can be thought of conveying 245 cents.
[10:24:57] dionysus69: but I had to adapt to the API, not to how the node works in the source
[10:25:46] dminuoso: dionysus69: correction its satoshis :)
[10:25:50] dminuoso: (at least on the blockchain)
[10:26:09] dminuoso: so you could think that "satoshis" are like cents and BTC are like dollars.
[10:26:18] dminuoso: except the factor is not 100 but 100 million.
[10:26:24] dionysus69: yea I see it like that :D
[10:26:53] dminuoso: "1.0000000001" is really just 1 bitcoin and 10 satoshis (dunno if I got the digits right, but you get the idea)
[10:27:04] dminuoso: So it's not "floating point". It's a rather precise denomination
[10:27:27] tvw: has joined #ruby
[10:27:44] dminuoso: "1.00000001BTC" is just a string representation for some amount of currency.
[10:28:28] dminuoso: With swapped endianness and a different comma sign some other folks might write it as: "CTB10000000_1"
[10:28:32] dminuoso: But it's still the same information inside.
[10:28:39] Radar: Other currencies do this same kind of precision but I don't remember which ones.
[10:29:10] dminuoso: ACTION pokes Radar with a radar
[10:29:20] Radar: ACTION slaps dminuoso around with a rusty lifetime
[10:29:27] Radar: *around a bt
[10:29:30] Radar: well, you know what I mean
[10:29:42] dminuoso: You borrowed that from some language, right?
[10:29:48] Radar: badum tish
[10:30:03] Radar: I remember distinctly having to deal with currencies that weren't two-digit-precise-after-the-decimal-point when working in ecommerce land.
[10:30:27] sytherax: has joined #ruby
[10:30:30] dminuoso: Radar: what does "two-digit-precise-after-the-decimal-point" mean?
[10:30:35] Radar: dminuoso: $10.45
[10:30:46] Radar: Not: $10.456
[10:30:55] dminuoso: The biggest problem I see with money is just the conflation of "representation" and "value"
[10:31:43] dminuoso: Radar: Ah yeah. Not a big issue if you just use rational.
[10:31:55] ur5us: has joined #ruby
[10:31:57] dminuoso: (or fractionals as they are sometimes called)
[10:32:02] Radar: i think it was the displaying of the money always rounded up to two decimal points
[10:32:19] Radar: It's a silly mistake. Like all software.
[10:33:02] dminuoso: Radar: we had such an exact bug in our tax software. It caused a real big shitstorm, eventually costing us in the 5 digits in man hours to fix it in all the necessary places.
[10:33:06] dionysus69: Usually bitcoin forks stick with 8 precision
[10:33:13] dminuoso: Reason? Our tax report was off by 2 cents.
[10:33:20] dionysus69: it's quite complicated I imagine to change that
[10:33:29] Radar: 5 digits in manhours? fuck
[10:33:32] dminuoso: *5 digits in EURs
[10:33:34] weird_error: has joined #ruby
[10:33:48] dminuoso: Still hilarious.
[10:34:02] Radar: hey at least your tax system is mostly sensible
[10:34:08] dminuoso: I dont know about that..
[10:34:13] dionysus69: ye that sounds expensive
[10:34:35] dionysus69: tell me the site you work for, I ll add it to my hosts file xD
[10:34:58] Radar: dionysus69: oh that's nice of you. So that the DNS server doesn't have to resolve the address every time you visit?
[10:35:20] Radar: dminuoso: at least it's not the US tax system where different zip codes have different tax _rates_ and _rules_
[10:35:28] dminuoso: Radar: The annoying thing was "it wasnt really an issue" or a "horrible bug" - just some tedious work. All because the tax report was off by 2 cents. But it's better to spend tons of money than to explain to the IRS why your report is off"
[10:35:29] Radar: dminuoso: in NYC, an uncut bagel is tax free. A cut bagel is taxed.
[10:35:40] dminuoso: Radar: Oh we have plenty of such things here too.
[10:35:45] dionysus69: I meant like, it would redirect me to google.com or something, but it's responsive jk ^.^
[10:35:59] dminuoso: Radar: https://image.stern.de/7225682/uncropped-620-520/c237a3f85876a065c51093155e7d210c/Lw/weihnachtsbaum-grafik.png
[10:36:03] Radar: dminuoso: iirc your tax system is tiered
[10:36:11] dminuoso: Radar: that's the correct flow chart to figure out the taxation of a christmas tree.
[10:36:17] Radar: hahahahaha
[10:36:32] Radar: Yes that sounds about right
[10:37:18] dminuoso: Radar: I dont think its fair to compare the US with Germany in that respect though.
[10:37:28] dminuoso: Structurally the US is closer to the EU
[10:37:33] Radar: dminuoso: well I can't think of many other respects where US would come out on top ;)
[10:37:43] dminuoso: Our countries just happen to have more sovereignity
[10:38:37] dminuoso: Radar: But different *zipcodes*.. is that different zip codes in the same state?
[10:38:42] Radar: dminuoso: correct
[10:39:20] Radar: dminuoso: And I can't find the map for it right now, but I know there's a map out there that lets you click around and it tells you the tax rate for that exact location. There's a city in Colorado that's split into two separate zip codes and the two different sides have two different tax rates.
[10:39:32] Radar: So you could _cross the street_ and be taxed _less_
[10:39:43] dminuoso: Haha thats hilarious
[10:39:53] cdunklau: dminuoso: germany has federal, state, district, and city/town/village laws right?
[10:42:08] dminuoso: cdunklau: We don't really have the notion of districts in the same sense that the US do.
[10:42:15] cdunklau: the US does too. taxes can be applied at each level
[10:42:28] cdunklau: dminuoso: sure you do. Kreis ~= County
[10:43:17] cdunklau: dminuoso: district is a generic word, county is the normal US-specific one
[10:43:40] cdunklau: except in Louisiana, they have parishes instead
[10:45:21] cdunklau: i just don't know what the rules are for taxation at the various levels in germany. In the US, each administrative level can levy their own taxes
[10:46:15] cdunklau: i'm just a filthy Ausländer, i pay whatever they tell me :P
[10:46:23] cdunklau: (in germany)
[10:46:34] aufi: has joined #ruby
[10:46:49] drale2k_: has joined #ruby
[10:47:00] apeiros: 12:30 Radar: I remember distinctly having to deal with currencies that weren't two-digit-precise-after-the-decimal-point when working in ecommerce land.
[10:47:02] papajo: has joined #ruby
[10:47:11] Radar: apeiros: yes that is something I said
[10:47:16] apeiros: Radar: bancs never use 2 digits of precision for currency, even if that's how the denomination works
[10:47:28] apeiros: i.e. even for dollar and euro, they use 3 digits
[10:47:40] Radar: I'd imagine it would be hard to accurately calculate rounding without the 3rd digit
[10:47:50] apeiros: and as for currencies with 3 digits, lira was one, but since that's now euro-zone :)
[10:47:53] cdunklau: dminuoso: ah looks like it's similar, according to wikipedia at elast: "The municipalities and the districts (Kreise) can decide on some minor local taxes like the taxation of dogs (Hundesteuer)."
[10:48:02] cdunklau: s/elast/least
[10:48:02] papajo: has left #ruby: ()
[10:48:10] apeiros: Radar: well, it's still not accurate with 3 digits. but the loss/diff is at least less.
[10:48:22] Radar: apeiros: they need to have 11 digits. That'll fix it
[10:48:40] apeiros: it won't. but… you knew that already.
[10:48:53] apeiros: I'm all for symbolic notation for money.
[10:49:01] apeiros: "this costs 3π$"
[10:50:10] Radar: I dunno that seems kinda irrational
[10:50:23] Radar: I mean it'd send people squar
[10:50:48] apeiros: ICOs can use complex numbers since their product is imaginary anyway.
[10:52:57] Karuna: has joined #ruby
[10:52:58] cdunklau: (what's an ICO)
[10:53:25] apeiros: initial coin offering
[10:57:51] Radar: oh sweet precious innocent soul
[11:01:43] vondruch_: has joined #ruby
[11:10:37] fmcgeough: has joined #ruby
[11:11:34] burgestrand: has joined #ruby
[11:14:40] dionysus69: dminuoso: just dropping this here
[11:14:56] dionysus69: this is the solution I came up with in case of user input
[11:14:59] dionysus69: ("0.3".to_d * 1000000).to_i
[11:15:12] dionysus69: so that is 300000 ada lovelaces
[11:15:53] dionysus69: service requires word64 haskell datatype, doesn't accept anything else
[11:15:57] VladGh: has joined #ruby
[11:16:08] dionysus69: which is a horrible name btw because at first I thought it was a string data type
[11:21:01] jamesaxl: has joined #ruby
[11:37:10] NL3limin4t0r: dionysus69: the reason it's called word, is not because it contains a string, but has to do with it's size
[11:37:14] NL3limin4t0r: see: https://stackoverflow.com/questions/16863333/what-is-the-point-word-type-in-c
[11:38:33] shinnya: has joined #ruby
[11:40:11] ldnunes: has joined #ruby
[11:41:36] ramfjord: has joined #ruby
[11:42:43] mguex: has joined #ruby
[11:44:13] dminuoso: dionysus69: Stop with these terrible hacks.
[11:44:47] dminuoso: dionysus69: You could use a simple regular expression that will probably work well enough.
[11:46:03] vondruch: has joined #ruby
[11:46:10] AJA4350: has joined #ruby
[11:47:33] c0mrad3: has joined #ruby
[11:48:26] dendazen: has joined #ruby
[11:50:58] dminuoso: dionysus69: https://eval.in/1019642
[11:54:13] apeiros: dminuoso: no anchors, sad.
[11:54:56] dminuoso: apeiros: Im too spoiled with parser combinators in Haskell that I forgot how to regex.
[11:55:19] millerti: has joined #ruby
[11:57:23] dminuoso: But yeah you are right :<
[11:58:00] Beams: has joined #ruby
[12:01:15] apparition47: has joined #ruby
[12:02:41] za1b1tsu: has joined #ruby
[12:03:14] za1b1tsu: Hello, anybody using RubyMine, is there a built in way to open a gem's folder as a project?
[12:03:24] dminuoso: apeiros: https://eval.in/1019688 better? =)
[12:04:10] apeiros: dminuoso: (without looking) you had a problem, you used a regex to solve it. you now have 2 problems 😂
[12:04:28] Zarthus: za1b1tsu: if it's in a vendor/ folder, it's already opened in your project.
[12:04:31] noron99: has joined #ruby
[12:04:36] dminuoso: apeiros: Someone should really write a good parser combinator implementation in Ruby.
[12:04:43] dminuoso: A monadic parser combinator with backtracking.
[12:04:46] apeiros: dminuoso: maybe somebody did?
[12:04:50] dminuoso: Nobody did :(
[12:04:59] apeiros: but nobody writes amazing code!
[12:05:32] apeiros: personally I prefer `raise blah unless md`
[12:05:41] apeiros: but that's just me
[12:05:55] dminuoso: apeiros: I've stopped post-if/unless because it hampers the reading flow.
[12:06:02] apeiros: also :larger and :lesser? I expected more from you 😄
[12:06:20] dminuoso: apeiros: such as?
[12:06:29] apeiros: dminuoso: interesting. I use them exactly because I like the reading flow. but really only if the condition is a single word.
[12:06:58] dminuoso: apeiros: a lot of ruby promotes "ruby code should read like english text"
[12:07:13] dminuoso: apeiros: the problem is that execution doesn't follow that direction
[12:07:20] tbuehlmann: that makes sense if you ask me
[12:07:24] tbuehlmann: see if at the end!
[12:07:55] za1b1tsu: Zarthus: my vendor folder has assets with javascript with stylesheets..
[12:08:01] dminuoso: Its a YMMV case I suppose.
[12:08:15] dminuoso: I even avoid `unless` in many cases in favour for `if !...~
[12:08:47] synthroid: has joined #ruby
[12:08:51] apeiros: dminuoso: fun, I'm actually not sure. I thought of significand and mantissa, but that's actually wrong for this.
[12:09:37] apeiros: dminuoso: I understand what you mean. there's a point in knowing before reading an instruction that it's only conditionally executed.
[12:10:39] dminuoso: apeiros: For what its worth, I did spend some thought on the naming of those capture groups. Ended up with lesser/greater because I didn't have any better words. :)
[12:10:42] apeiros: and tbh, with raise, I often use a 3 line statement because the exception message is too long for it to fit into my "suffix if/unless is fine"
[12:11:29] apeiros: dminuoso: maybe integer & fraction? dunno. I was just pulling your leg anyway :)
[12:11:48] dminuoso: apeiros: I only responded because I was hoping that maybe you had a better idea =)
[12:12:02] apeiros: and I faaaaailed, oh nooooes :(
[12:12:09] dminuoso: integer/fraction might actually work
[12:12:15] dminuoso: but lets not bikeshed this
[12:12:21] apeiros: given that I've written code like that for certainly two dozen times, you'd think I'd remember which words I used.
[12:13:03] dminuoso: apeiros: By the way: perl-style $ groups or MatchData?
[12:13:14] sytherax: has joined #ruby
[12:13:21] apeiros: $ should die
[12:13:36] apeiros: and more nuanced: $ should be available via command line option --golf
[12:13:55] apeiros: and that command line option should also load some standard libs
[12:14:05] apeiros: idea being: allow to be ultra-short for one-off scripts
[12:14:50] dminuoso: apeiros: I found that even in those cases they blow.
[12:15:07] apeiros: so e.g. you can write: `ruby -Gpe 'gsub(blah) { $1.upcase }'`
[12:15:23] dminuoso: apeiros: One truth that programmers dont like to admit, writing a few characters is basically not the issue. Even when you write 200 lines of code, chances are it might take you a day to write it.
[12:15:29] apeiros: dminuoso: yeah, same. IMO the only place is really just with -e
[12:15:44] fmcgeough: has joined #ruby
[12:15:49] apeiros: (-e could imply --golf :D)
[12:15:57] dminuoso: Or sometimes even a week while you ponder about your code base and its implications.
[12:16:03] Beams_: has joined #ruby
[12:16:46] dminuoso: My entire focus on code style boils down to readability, especially when I have to see the code 5 years later from now, having forgotten its meaning entirely.
[12:18:03] cdunklau: dminuoso: how about a PEG https://github.com/evanphx/kpeg
[12:18:10] cdunklau: (i have no idea how good that lib is)
[12:18:24] apeiros: dminuoso: mine has split in 2 variants: code for myself, and code for the team
[12:18:35] apeiros: the latter is a lot less "clever"
[12:18:41] dminuoso: cdunklau: monadic parser combinators feel more natural to me
[12:18:54] cdunklau: there's that damn word again :D
[12:19:01] apeiros: and the former, I go for more readability than a couple years ago too. same reason as you.
[12:19:16] dminuoso: cdunklau: it's a ridiculously simple concept to use.
[12:19:21] apeiros: but I'll use things I know I understand, but which would require explanations in a team.
[12:19:50] dionysus69: ok thanks for that method dminuoso :)
[12:21:16] gnufied: has joined #ruby
[12:22:23] dminuoso: cdunklau: https://gist.github.com/dminuoso/6e411676f681471ab12bb7d1f2bfdb58 =)
[12:22:58] elsurudo: has joined #ruby
[12:24:23] cdunklau: dminuoso: jesus i do *not* know ruby well enough to even begin understanding that :d
[12:24:35] cdunklau: or is that even ruby
[12:24:42] dminuoso: cdunklau: https://gist.github.com/dminuoso/6e411676f681471ab12bb7d1f2bfdb58#file-f-rb-L5-L8
[12:24:50] dminuoso: "first get some digits"
[12:25:06] dminuoso: when parsed, they will be available in the variable "eur" later
[12:25:15] dminuoso: then parse a comma, disregard that result
[12:25:24] dminuoso: thgen parse some digits, they will be avialable in the variable "cents" later
[12:25:39] dminuoso: then parse an optional EUR sign, and the result of the entire parser is some Eur object.
[12:25:58] cdunklau: dminuoso: is this something that works, or something that you wish worked? :)
[12:26:05] dminuoso: cdunklau: I have some working implementations for that.
[12:26:29] cdunklau: dminuoso: so the >-> and >> bits... are those just methods or what
[12:26:45] dminuoso: cdunklau: >> is just a method, and the >-> is just a visual trick Im playing on you.
[12:26:52] dminuoso: the last is just the > method
[12:26:59] dminuoso: followed by a stabby lambda -> ... {}
[12:27:11] cdunklau: "stabby lambda"?!?
[12:27:55] dionysus69: this should return 200_000
[12:27:56] dionysus69: https://eval.in/1019706
[12:28:07] sytherax: has joined #ruby
[12:28:07] drale2k_: has joined #ruby
[12:28:38] dminuoso: cdunklau: https://gist.github.com/dminuoso/6e411676f681471ab12bb7d1f2bfdb58 this is an annotated version
[12:29:18] dminuoso: cdunklau: so the "combinator" part refers to the fact that you begin to supply certain primitives like `maybe` or `many` and `some` that take an existing parser and somehow "enhance" it
[12:29:30] dminuoso: char(',') is a parser that parses exactly one comma
[12:29:48] dminuoso: maybe takes a parser that may fail, and backtracks if necessary
[12:30:01] cdunklau: wouldn't it be better to indent that
[12:31:03] dminuoso: If you prefer sure.
[12:34:17] cdunklau: dminuoso: would this be a reasonable indentation? https://gist.github.com/cdunklau/588151dd6de2a040941d87e9eddb8c04
[12:34:24] dminuoso: cdunklau: No.
[12:34:58] dminuoso: cdunklau: One way to think of monads is "programmable semicolons"
[12:35:08] dminuoso: cdunklau: So there's a deep reason why I intentionally line them up like that.
[12:36:33] dminuoso: cdunklau: So the trick is: In a tradicional scenario you might write: eur = digits; char(','); cents = digits; maybe(char('€')); return Eur.new(eur, cents)
[12:36:57] alex``: has joined #ruby
[12:37:03] dminuoso: cdunklau: However: How do I capture this parser as a first class value that I can pass it to other combinators? How do you backtrack on failure?
[12:37:52] dminuoso: So in a twisted sense each >-> acts as a programmable assignment =
[12:38:08] dminuoso: (followed by a programmable semicolon)
[12:38:14] dminuoso: while >> acts as a programmable semicolon
[12:38:40] cdunklau: i think this is so difficult for me because i'm not used to expression langauges
[12:41:14] dminuoso: cdunklau: https://gist.github.com/dminuoso/6e411676f681471ab12bb7d1f2bfdb58
[12:41:56] dminuoso: cdunklau: So these types of parsers are common in Haskell. What I write as >-> is called >>= in Haskell, and >> is the same. Haskell however has a syntax sugar that makes it a bit more readable.
[12:42:45] dminuoso: cdunklau: the cool thing in the end is, that `eurParser` itself is just a simple parser like digits or char(',')
[12:44:10] Beams: has joined #ruby
[12:44:47] dminuoso: cdunklau: https://gist.github.com/dminuoso/2a3af36e9525e8792e7c0a17a3311afa so you can use it to build larger parsers..
[12:45:41] cdunklau: i get the composibility part
[12:45:49] kapil___: has joined #ruby
[12:45:50] cdunklau: i just don't get how the fuck this code works
[12:46:45] dminuoso: cdunklau: Are you familiar with ML style type annotations?
[12:46:53] cdunklau: dminuoso: hahah no
[12:46:59] dminuoso: cdunklau: It's very simple
[12:47:13] cdunklau: dminuoso: you keep using that word. i do not think it means what you think it means :)
[12:47:42] dminuoso: cdunklau: Formally a parser can be thought of a function that `takes a string` and `returns a pair of a result and the remaining string`
[12:48:19] cdunklau: ok that's clear
[12:48:21] dminuoso: char = -> str { c, rest = str; return [c, rest] }
[12:48:40] dminuoso: is a simple parser, one that parses exactly one parser off a stream
[12:48:56] cdunklau: dminuoso: -> str { ... } is the lambda, right?
[12:49:16] dminuoso: however that's not good enough because we dont know how to describe failure or backtracking
[12:49:23] dminuoso: so we augment that with a slight twist
[12:49:43] dminuoso: a parser is a functoin that `takes a string` and `returns a *list* of pairs, each of which consists of a possible result and the remaining string`
[12:50:08] dminuoso: each element in that list represents "one possible way to parse it, with the respective result and remaining stream"
[12:50:16] cdunklau: c, rest = str is that a real thing or shorthand for c, rest = str[0], str[1:] or so
[12:50:25] dminuoso: Yes and yes.
[12:50:36] dminuoso: or.. well. shorthand
[12:50:42] dminuoso: good catch =)
[12:50:55] dminuoso: by definition we say:
[12:51:04] dminuoso: if a parser returns an empty list, it denotes a failed parse
[12:51:14] dminuoso: if a parser returns a list of exactly one pair, it denotes a success
[12:51:22] dminuoso: if a parser returns a list of multiple pairs, it denotes an ambiguous parse
[12:51:47] dminuoso: so first we say we have some `Pair = Struct.new(:result, :rest)`
[12:51:55] dminuoso: so our char parser would actually look like
[12:52:45] dminuoso: char = -> str { c, rest = str[0], str[1..]; return [Pair.new(c, rest)]; }
[12:53:32] dminuoso: cdunklau: so far?
[12:53:37] cdunklau: following yes
[12:53:55] dminuoso: cdunklau: so now we define a function that sequences two parsers
[12:53:59] dminuoso: lets call it sequence
[12:54:06] dminuoso: sequence = -> parser1, parser 2 { ... }
[12:54:08] dminuoso: how would you implement this?
[12:54:13] dminuoso: sequence = -> parser1, parser2 { ... }
[12:54:47] jrafanie: has joined #ruby
[12:55:52] cdunklau: { return [parser2(pair.rest) for pair in parser1(str)]; }
[12:56:00] cdunklau: if list comps are a thing
[12:56:11] dminuoso: cdunklau: that wont do it.
[12:56:12] cdunklau: or just some mappy thing
[12:56:15] dminuoso: remember you have to return a *parser*
[12:56:25] dminuoso: so start from that fact.
[12:56:54] cdunklau: { return -> str { return [parser2(pair.rest) for pair in parser1(str)]; }; }
[12:57:10] cdunklau: sequence = -> str { return -> str { return [parser2(pair.rest) for pair in parser1(str)]; }; }
[12:57:20] dminuoso: cdunklau: I think that pseudo code looks about right.
[12:57:39] dminuoso: well, except you didnt correctly build the Pair.
[12:57:56] sytherax: has joined #ruby
[12:58:09] cdunklau: well no i did. the pair is the thing parser2 returns
[12:58:25] cdunklau: but i don't know if that's correct
[12:58:32] dminuoso: Ah right. No it looks good.
[12:58:37] dminuoso: cdunklau: So that's basically just >>. `q = parser1 >> parser2` gives you a new parser back.
[12:58:47] dminuoso: One that (internally) first executes parser one, and then parser two.
[12:58:57] dminuoso: cdunklau: So next up lets do the monadic part.
[12:59:19] dminuoso: Now assume you have a function f
[12:59:23] dminuoso: f has this shpape:
[13:00:03] dminuoso: "take the result from a previous parser, and then *give a parser back*"
[13:00:37] Beams_: has joined #ruby
[13:00:46] cdunklau: so that's like (Pair[]) -> Parser ?
[13:01:04] dminuoso: cdunklau: In ML lingo you'd consider Parser a parametrized type
[13:01:16] dminuoso: so `Parser Char` would be some `String -> [(Char, String)]`
[13:01:42] dminuoso: So your sequence has the shape: Parser a -> Parser b -> Parser b
[13:01:53] amar_: has joined #ruby
[13:01:54] dminuoso: Now you want some `Parser a -> (a -> Parser b) -> Parser b`
[13:02:31] cdunklau: you lost me there. give me a bit
[13:02:37] cdunklau: let me roll it around in my head
[13:03:03] dminuoso: cdunklau: it may be easier if you try to define some concrete parser first
[13:03:22] dminuoso: though.. its easier to write them if you have that function.
[13:03:38] cdunklau: but your euro parser thing
[13:04:16] dminuoso: cdunklau: >-> is that thing. > is a function that takes a lambda. that lambda gets the *result* of the previous parser (if it succeeds), and then makes a decision on a new parser to run afterwards.
[13:04:39] dminuoso: cdunklau: Its the same thought process of >> really
[13:04:41] cdunklau: \d+,\d{2}€? is the regex right?
[13:04:42] leitz: has joined #ruby
[13:05:01] dminuoso: Somewhat similar yes.
[13:05:46] samosaphile: is there a reason why haskell has no or few libraries/frameworks but OOP stuff (java, python, c# / .NET, etc) have tons? despite haskell being older language? well, i guess you could say java was backed by sun/oracle and c# by MS, which helped but ruby/python weren't ...
[13:06:05] dminuoso: samosaphile: Haskell has a a very healthy set of mature libraries.
[13:06:26] dminuoso: Most of them are well documented and many of exceptional quality.
[13:06:46] cdunklau: samosaphile: python and ruby aren't as scary-looking
[13:07:05] cdunklau: dminuoso: let me mull this over for a bit
[13:07:05] dminuoso: cdunklau: You should try to implement the >-> thing by the way. =)
[13:07:20] dminuoso: cdunklau: Feel free to do it in python instead if it helps.
[13:09:06] dminuoso: cdunklau: It may be easier to ignore the `list` at first.
[13:09:14] dminuoso: (And then extend to allow for the list afterwards)
[13:09:28] samosaphile: what happens if you need a library in python/ruby but write something in haskell? is it possible to use libraries from different languages?
[13:09:55] dminuoso: Not with Haskell at the moment.
[13:10:17] samosaphile: k, was just curious
[13:10:38] gustavn64: has joined #ruby
[13:11:01] dminuoso: samosaphile: Here our issues are actually switching to Haskell. So our rails apps start calling into Haskell APIs that listen on local unix domain sockets
[13:11:09] dminuoso: That way we can gradually switch over.
[13:12:00] dminuoso: cdunklau: While you are at it, you should also write the function `pure` which takes one argument and then returns a parser that readily has that result, and does not consume any input
[13:12:19] gustavn64: I'm creating a little interpreter for a programming language, in Ruby, and I want to represent the value nil (my kind of nil, not Ruby's). But I don't want to conflate my kind of nil with Ruby's kind of nil (since both occur in my interpreter). What would be a good, idiomatic way to do this?
[13:12:38] gustavn64: Just define a class like this?
[13:12:41] gustavn64: class Nil; end
[13:12:46] conta1: has joined #ruby
[13:12:57] dminuoso: gustavn64: what kind of interpreter are you writing?
[13:12:59] gustavn64: To be honest, I don't really need a new instance for every time, either
[13:13:03] dminuoso: gustavn64: a stack machine? some AST interpreter?
[13:13:13] gustavn64: dminuoso: AST
[13:13:40] dminuoso: gustavn64: You could have some `NilNode = Object.new(ASTNode)`
[13:13:41] karapetyan: has joined #ruby
[13:13:57] dminuoso: NilNode = Class.new(ASTNode)
[13:14:06] dminuoso: Assuming you have some base class to represent your AST nodes with
[13:14:13] elsurudo: has joined #ruby
[13:14:18] cdunklau: dminuoso: i suspect this would be difficult to write reasonable in python because of how badly lambda is crippled... and a decorator API would probably look awful
[13:14:34] dminuoso: cdunklau: just do it manually, its not a beauty contest.
[13:15:07] dminuoso: cdunklau: And its a bit annoying to read, but the entire purpose is to hide this plumbing behind >
[13:16:11] gustavn64: dminuoso: Yeah I guess that's kind of what I thought of. I don't have a common base class yet, but I see your point
[13:16:34] gustavn64: The problem is that it doesn't really feel like this right thing to do. I won't need a new instance if NilNode each time
[13:17:04] gustavn64: Oh wait, I guess I could actually do:
[13:17:08] gustavn64: NilNode = Object.new
[13:17:39] gustavn64: How's that? Good Ruby style?
[13:18:32] dminuoso: gustavn64: If that works for you then sure.
[13:19:00] dminuoso: 15:16 gustavn64 | The problem is that it doesn't really feel like this right thing to do. I won't need a new instance if NilNode each time
[13:19:21] dminuoso: That wont be an issue as you can simply use a global `Nil = NilNode.new` - the point is to have a common interface you can later use to interact with the AST
[13:20:15] dminuoso: cdunklau: https://gist.github.com/dminuoso/cc021f7ba9ea9748333ab47e2d6203cc you can use this
[13:20:22] gustavn64: dminuoso: Ah. Is there any way to create the class NilNode, with methods and everything, but not giving it a name (only using it to instanciate Nil)?
[13:20:50] dminuoso: cdunklau: Just make some NilNode = Class.new(...)
[13:20:57] dminuoso: cdunklau: Even if just for the reason you might want to ask `node.class` later on ;)
[13:23:11] dminuoso: Sorry gustavn64 =)
[13:25:07] samosaphile: dminuoso: what are your thoughts on python and c# / .NET ? do you equally detest them like javascript and ruby / rails? :P
[13:25:17] dminuoso: samosaphile: Yes.
[13:25:32] samosaphile: i don't understand dminuoso if you really hate web so much, why not just use rust instead?
[13:26:20] dminuoso: samosaphile: Im in the process of switching some of our parts to Haskell.
[13:27:09] gil_: has joined #ruby
[13:27:09] gil_: has joined #ruby
[13:28:39] mzo: has joined #ruby
[13:30:55] kmurphy4: has joined #ruby
[13:30:55] bmurt: has joined #ruby
[13:31:07] theRoUS: has joined #ruby
[13:31:46] aupadhye: has joined #ruby
[13:35:04] saTchymoto: has joined #ruby
[13:36:44] gustavn64: dminuoso: Alright, thanks for the tips
[13:36:52] gustavn64: dminuoso: Why do you hate C# btw? haha
[13:37:39] dminuoso: gustavn64: I like languages that actively pursue some goal and design decisions. The majority of mainstream languages are very close clones of one another.
[13:37:51] dminuoso: Just try programming in Prolog for a month and you will see what I mean.
[13:37:57] aufi: has joined #ruby
[13:38:10] gustavn64: dminuoso: I have used Prolog and I enjoyed it a lot
[13:38:13] Rapture: has joined #ruby
[13:38:37] gustavn64: Yeah I mean, I was mainly curious. I hate most mainstream languages in a mild sense too, but that's probably because I hate software engineering
[13:38:43] cdunklau: dminuoso: so far https://gist.github.com/cdunklau/59358228ec4bc8ee6fa3f1e5e97f3557
[13:39:34] burgestrand: has joined #ruby
[13:39:47] cdunklau: i'm still thinking about what you mean by the f with shape "take the result from a previous parser, and then *give a parser back*"
[13:40:50] dminuoso: cdunklau: check my last gist
[13:40:58] dminuoso: "# Runs one parser, feeds the result into the function, and then runs the resulting parser."
[13:41:06] dminuoso: the resulting thing must be a parser. too.
[13:47:03] cdunklau: dminuoso: sequence doesn't strictly need to be curried though, right?
[13:50:18] griffindy: has joined #ruby
[13:50:41] dminuoso: cdunklau: Nope.
[13:52:14] sytherax: has joined #ruby
[13:53:10] cdunklau: dminuoso: what's kf here bind = -> parser, kf { ... }.curry
[13:53:21] dminuoso: cdunklau: thats just the name of that function
[13:53:31] dminuoso: the function that accepts the result of the previous parser, and gives you a new parser to run back
[13:54:16] cdunklau: dminuoso: "result of the previous parser" meaning the list of pairs?
[13:54:50] dminuoso: cdunklau: especially in FP we tend to not think of a list as "multiple" but rather as some "fuzzy/non-deterministic" answer
[13:55:08] dminuoso: that is [1,2,4] is a number (but we're not quite sure *which*)
[13:55:25] dminuoso: and `map` lets you interact with that number (and since we're not sure *which* we apply it to each number)
[13:56:48] dminuoso: Does this help?
[13:56:59] bmurt: has joined #ruby
[13:57:01] cdunklau: dminuoso: that's a rather long-winded way of saying "yes" :)
[13:57:14] cdunklau: but that does illuminate things, sure
[14:00:27] pastorinni: has joined #ruby
[14:02:04] erlendf: has joined #ruby
[14:02:05] MihaRekar: has joined #ruby
[14:03:39] cdunklau: dminuoso: so bind is just this? https://gist.github.com/cdunklau/59358228ec4bc8ee6fa3f1e5e97f3557#file-foo-py-L45
[14:04:06] dminuoso: cdunklau: Almost.
[14:04:24] dminuoso: cdunklau: Its kind of wrong
[14:04:24] za1b1tsu: has joined #ruby
[14:04:39] dminuoso: cdunklau: So `kf` first want a single *result*
[14:04:53] dminuoso: Not a list of ParsePair
[14:04:59] cdunklau: oh that's what you meant by map
[14:05:46] dminuoso: cdunklau: and remember that `kf` only wants the raw *result*, not the pair
[14:06:02] dminuoso: (this is an important part to the DSL)
[14:06:32] dviola: has joined #ruby
[14:07:33] livcd: is rubinius still a thing ?
[14:07:48] snickers: has joined #ruby
[14:08:11] millerti: has joined #ruby
[14:09:01] dminuoso: cdunklau: then when you are done, we'll get rid of your clunky digits and char parser and start with combinators instead.
[14:09:15] dminuoso: You'll be amazed I promise =)
[14:09:52] cdunklau: so when i map kf i get a list of parsers...
[14:10:17] cyberg: has joined #ruby
[14:10:17] cdunklau: [kf(pp.result) for result in parserA(string)]
[14:10:30] dminuoso: what is pp?
[14:10:40] cdunklau: err s/result/pp/
[14:10:55] cdunklau: [kf(pp.result) for pp in parserA(string)]
[14:11:03] dminuoso: cdunklau: Alright.. but you dont want a list of parser, you want a list of pairs!
[14:11:20] cdunklau: dminuoso: OH
[14:11:29] dminuoso: Because again, you are *constructing a parser*
[14:11:37] cdunklau: [kf(pp.result)(pp.rest) for pp in parserA(string)]
[14:11:44] dminuoso: Voila. Your first monad.
[14:11:52] dminuoso: Now implement `pure`
[14:11:58] dminuoso: To round it up
[14:13:53] dminuoso: cdunklau: the point of bind is basically this:
[14:14:16] ramfjord: has joined #ruby
[14:14:38] cdunklau: dminuoso: pure is... ready_result -> string -> [Pair(ready_result, string)]
[14:15:01] dminuoso: cdunklau: it creates an "effect" free parser (because it doesnt consume any input)
[14:15:05] dminuoso: hence "pure"
[14:15:22] dminuoso: cdunklau: alright. now write a simple parser item that consumes a single character and gives that character as a result
[14:15:45] dminuoso: (you'll need to develop a small set of basic utilities - those are usually all provided by a combinator libraries)
[14:16:25] cdunklau: dminuoso: a single specific character or just the first one
[14:16:30] dminuoso: the first one.
[14:16:49] dminuoso: call it `item`
[14:17:45] dminuoso: then write a function `satisfy` that takes a predicate, a parser, and then runs a parser, tests the result with the predicate. "fail" if the predicate gives you a false, and "return" the result if gives you a true. You will need to use `bind` and `pure`
[14:18:03] dminuoso: (remember what "parse failure" means?)
[14:18:18] dminuoso: then you can write some `isChar` function using `satisfy`
[14:18:31] cdunklau: https://gist.github.com/cdunklau/59358228ec4bc8ee6fa3f1e5e97f3557#file-foo-py-L57
[14:18:38] cdunklau: item_parser
[14:18:45] dminuoso: now write satisfy.
[14:21:04] cdunklau: dminuoso: satisfy returns a parser that does the thing right?
[14:21:33] dminuoso: cdunklau: satisfy :: (a -> Bool) -> Parser a -> Parser a
[14:22:07] subroot: has joined #ruby
[14:22:16] dminuoso: cdunklau: it returns a parser that.. runs the passed parser, and uses the predicate to determine whether it should fail or not.
[14:22:43] dminuoso: cdunklau: at this point you will *stop* to build parsers from scratch, and instead use the existing functions
[14:22:53] dminuoso: (so that you start to lose the focus on the exact inner workings)
[14:23:21] dminuoso: cdunklau: `bind` is my > by the way.
[14:23:32] dminuoso: so when I write: digits >-> d { ... }
[14:23:40] dminuoso: then > is just the infix `bind`
[14:23:43] dminuoso: -> d { .. }
[14:24:57] cdunklau: oh bind has to be curried doesn't it
[14:25:15] dminuoso: it might be useful, perhaps not *shrugs*
[14:25:44] dminuoso: digits > (-> d { ...})
[14:25:50] dminuoso: bind(digits, (-> d { ...})
[14:26:27] dminuoso: cdunklau: And if you want you can also reimplement `sequence` in terms of `bind`
[14:28:01] dminuoso: cdunklau: You might find this paper enlightening: http://www.cs.nott.ac.uk/~pszgmh/monparsing.pdf
[14:28:15] dminuoso: Even though its in haskell its mild. You should be able to read it.
[14:30:16] cdunklau: this feels like one of those riddles that i'm so terrible at, where once you hear the solution it's all "duuuuuh that's obvious *now*"
[14:35:04] karapetyan: has joined #ruby
[14:37:33] Beams: has joined #ruby
[14:38:03] sytherax: has joined #ruby
[14:38:41] spooky_d: has left #ruby: ()
[14:42:35] QCF: has joined #ruby
[14:46:43] aufi: has joined #ruby
[14:48:21] grilix_: has joined #ruby
[14:59:21] cdunklau: dminuoso: that did help. made me realize my bind is wrong, it doesn't concat
[14:59:57] rideh: has joined #ruby
[15:00:10] m1st3rwr0ng: has joined #ruby
[15:03:23] chouhoulis: has joined #ruby
[15:05:05] banisterfiend: has joined #ruby
[15:08:00] iceden: has joined #ruby
[15:08:53] venmx: has joined #ruby
[15:10:03] workmad3: has joined #ruby
[15:11:34] samosaphile: hmm, doesn't seem haskell is great for gui stuff, http://www.scs.stanford.edu/14sp-cs240h/projects/martinez.pdf https://www.reddit.com/r/haskell/comments/3z6961/designing_a_gui_library_purely_in_haskell/cyjskts/
[15:18:34] mzo: has joined #ruby
[15:20:28] tcopeland: has joined #ruby
[15:21:05] dminuoso: cdunklau: Ah right.
[15:21:25] dminuoso: cdunklau: I dont have much experience with Python, so I just skimmed the code.
[15:21:32] dminuoso: It looked morally right =)
[15:22:38] dminuoso: cdunklau: Once you have established a rich toolset of combinators, they really do take off.
[15:22:52] dminuoso: If they are monadic they are strictly more powerful than recursive descent parsers, but just as easy to use.
[15:23:38] dminuoso: Do take note that efficient implementations are *much* harder if you want any useful diagnostics, the ability to recover from failed parses, and performance.
[15:26:34] cdunklau: dminuoso: so what's the point :)
[15:26:47] dminuoso: cdunklau: They are really comfortable to write
[15:26:50] dminuoso: Even for small things
[15:26:53] dminuoso: Or for networking protocols
[15:26:56] troys: has joined #ruby
[15:26:57] dminuoso: Or for complex parsing situations
[15:27:04] cdunklau: so are PEGs
[15:27:36] cdunklau: (PEGs are the only parser thingies used, so i don't really know what i'm talking about)
[15:27:46] cdunklau: s/used/i've used/
[15:28:56] dminuoso: cdunklau: parser combinators are a lot cooler because your parsers are first class values
[15:39:12] jcarl43: has joined #ruby
[15:44:47] QCF: has joined #ruby
[15:46:26] yokel: has joined #ruby
[15:50:18] dbugger__: has joined #ruby
[15:53:54] synthroid: has joined #ruby
[15:57:12] venmx: has joined #ruby
[15:59:19] desperek: has joined #ruby
[15:59:47] Karuna: has joined #ruby
[16:01:16] banisterfiend: has joined #ruby
[16:01:46] kapil___: has joined #ruby
[16:05:17] WAFFLEMAKER3000: has joined #ruby
[16:07:08] Mike11: has joined #ruby
[16:13:41] zenspider: has joined #ruby
[16:14:30] darkhanb: has joined #ruby
[16:17:38] cschneid: has joined #ruby
[16:19:35] venmx: has joined #ruby
[16:20:56] clemens3_: has joined #ruby
[16:21:29] kmurphy4: has joined #ruby
[16:29:34] aufi: has joined #ruby
[16:29:58] bauruine: has joined #ruby
[16:32:04] amar_: has joined #ruby
[16:36:14] conr_: has left #ruby: ()
[16:36:37] intheclouddan: has joined #ruby
[16:45:50] rabajaj: has joined #ruby
[16:46:01] akaiiro: has joined #ruby
[16:46:03] rabajaj: can anyone help me out with File.join method
[16:46:25] rabajaj: if I dont know the absolute path to the file then can I use File.join
[16:47:03] apeiros: rabajaj: yes
[16:47:19] apeiros: File.join is mostly just arguments.join(PathSeparator)
[16:47:41] j0bk: has joined #ruby
[16:47:46] rabajaj: assume i have a variable `x` in which i have path `/tmp/exports`. I want to access a file that is created in `/tmp/exports/something_i_don_know/here is the file`
[16:48:23] rabajaj: apeiros, if i do this Dir["#{x}/*/*/*.iso"] i get the path i want
[16:48:38] rabajaj: can we convert this into File.join ?
[16:49:14] apeiros: Dir[File.join(x, "*", "*", "*.iso")]
[16:49:46] rabajaj: letme try this :)
[16:49:49] raynold: has joined #ruby
[16:50:43] rabajaj: apeiros, woah :) thanks
[16:52:36] dionysus69: has joined #ruby
[16:52:45] sanscoeur: has joined #ruby
[16:53:57] orbyt_: has joined #ruby
[16:56:32] workmad3: has joined #ruby
[16:57:09] beefjoe: has joined #ruby
[16:58:35] wontruefree: has joined #ruby
[17:00:57] nfk: has joined #ruby
[17:02:48] baweaver_away: G'morning apeiros
[17:02:56] cadillac_: has joined #ruby
[17:02:57] apeiros: moin baweaver
[17:03:00] baweaver: There we go, that feels better
[17:03:19] baweaver: Quick challenge / tip for kicks - https://twitter.com/keystonelemur/status/1006582160516526080
[17:03:31] baweaver: Now my prefill list for daily tips is empty D:
[17:03:53] apeiros: rot13 with tr?
[17:03:57] baweaver: Time to go raid Set and Struct for fun :D
[17:07:09] apeiros: oh wow, it's in the text. lol, I only looked at the code :D
[17:07:42] apeiros: what's a "tip for kicks"?
[17:10:14] jottr: has joined #ruby
[17:12:14] Hanma[m]: has joined #ruby
[17:12:15] bascht: has joined #ruby
[17:12:15] aviraldg: has joined #ruby
[17:12:15] jonjits[m]: has joined #ruby
[17:12:15] redlegion[m]: has joined #ruby
[17:12:15] luna_x[m]: has joined #ruby
[17:12:15] KevinMGranger: has joined #ruby
[17:12:15] velu_aon[m]: has joined #ruby
[17:12:15] Giphy[m]: has joined #ruby
[17:12:15] haylon_: has joined #ruby
[17:12:16] turt2live: has joined #ruby
[17:12:16] karapetyan: has joined #ruby
[17:12:22] iceskins[m]: has joined #ruby
[17:12:22] zalipuha[m]: has joined #ruby
[17:13:56] Cork: has joined #ruby
[17:15:16] baweaver: colloquialism "for fun"
[17:16:17] baweaver: Not sure if this one is a bug yet or not, but setting default will wipe default proc
[17:16:22] ellcs: has joined #ruby
[17:16:22] baweaver: (on a Hash)
[17:16:35] baweaver: I half think it's expected, because default value is checked for first.
[17:17:24] baweaver: >> h = Hash.new { |h,k| h[k] = 5 }; [h.default_proc, h.default, h.default = nil, h.default_proc]
[17:17:24] ruby[bot]: baweaver: # => [#<Proc:0x41219940@/tmp/execpad-d40a36ffb44d/source-d40a36ffb44d:2>, nil, nil, nil] (https://eval.in/1019958)
[17:17:37] jamesaxl: has joined #ruby
[17:17:57] baweaver: implied vs explicit nil that is
[17:20:46] FernandoBasso: has joined #ruby
[17:22:57] jottr: has joined #ruby
[17:24:38] orbyt_: has joined #ruby
[17:24:40] griffindy: has joined #ruby
[17:26:50] orbyt_: has joined #ruby
[17:38:14] nfk: has joined #ruby
[17:38:36] amar_: has joined #ruby
[17:39:42] wmoxam: has joined #ruby
[17:43:29] apeiros: baweaver: iirc it was considered a bug when it didn't
[17:43:57] apeiros: you can only have one method of default, and setting one will reset the other to nil iirc
[17:45:34] apeiros__: has joined #ruby
[17:46:41] lxsameer: has joined #ruby
[17:46:55] ramfjord: has joined #ruby
[17:47:20] Paraxial: has joined #ruby
[17:50:02] baweaver: mm, yeah, that's what I was thinking
[17:50:23] ferr: has joined #ruby
[17:50:51] sameerynho: has joined #ruby
[17:50:55] baweaver: apeiros__: Y'know if methods returning symbol names changed the way annotations are written? Most of the implementations I'm seeing rely on method_added
[17:51:46] apeiros: problem is that you can't just do "some_annotation\ndef foo", you have to "some_annotation def foo"
[17:51:55] apeiros: so chaining multiple becomes ugly quick
[17:52:00] apeiros: (or you use \ trick)
[17:52:39] apeiros: I have only seen rare cases of DSLs which make use of def's returning symbols.
[17:53:20] clemens31: has joined #ruby
[17:54:32] banisterfiend: has joined #ruby
[17:55:11] Ryzokuken: has joined #ruby
[17:58:20] karapetyan: has joined #ruby
[17:58:49] chouhoul_: has joined #ruby
[18:02:20] wontruefree: has joined #ruby
[18:02:36] ramfjord_: has joined #ruby
[18:04:04] jrich523: https://gist.github.com/jrich523/3afa7a06f87da0e61f9e2f7102cfcc53 this feels.... stupid.. it works... but... any..hmm... more ruby'ish ways to do it? seems like having the array definition like that is stupid
[18:04:17] baweaver: Admittedly I tend to do `private def ...` on occasion
[18:04:51] jrich523: also, for line 7, that came up yesterday, but all the suggestions were to new (2.0, everything else was 2.1 or 2.3)
[18:05:22] mikecmpbll: has joined #ruby
[18:05:51] jrich523: hmm i was considering that, but the result is from an http request, client.data (just pushed in to "nodes")
[18:05:57] baweaver: kvms.concat nodes.map do |n|
[18:06:02] jrich523: so the map might get dicey since its a WAY differnt object?
[18:06:32] baweaver: making an array and doing an each/push is already a map
[18:06:55] jrich523: hmm so im more so confusing map vs map!
[18:07:01] jrich523: let me play with that, thanks :)
[18:07:12] Unknown2: has joined #ruby
[18:16:24] shenghi: has joined #ruby
[18:16:41] cliluw: has joined #ruby
[18:18:47] samort7: has joined #ruby
[18:19:38] mtkd: has joined #ruby
[18:23:08] cthulchu: what is ::?
[18:23:46] bmurt: has joined #ruby
[18:24:24] \void: has joined #ruby
[18:25:18] cthulchu: it's weird though
[18:25:22] cthulchu: a little bit weird
[18:25:29] cthulchu: cuz I would expect a . to do it
[18:25:31] Eiam: >>Kernel::puts.object_id; puts.object_id
[18:25:32] ruby[bot]: Eiam: # => ...check link for more (https://eval.in/1020018)
[18:25:58] Eiam: it specifies the module
[18:26:13] cthulchu: and . wouldn't work with modules?
[18:26:15] Eiam: . is not for specifying a module, its for accessing a method on an instance
[18:26:15] jenrzzz: has joined #ruby
[18:26:16] jenrzzz: has joined #ruby
[18:26:23] cthulchu: in a class...
[18:26:42] cthulchu: I'm reading this: https://stackoverflow.com/questions/3009477/what-is-rubys-double-colon?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
[18:26:46] Eiam: cthulchu: yes, you can write >>Kernel.puts
[18:26:57] cthulchu: the dude uses :: to access a constant within a class
[18:27:19] Eiam: :: resolves scope
[18:27:26] Eiam: here, this describes it.
[18:27:29] Eiam: https://stackoverflow.com/questions/11043450/vs-dot-vs-double-colon-for-calling-a-method
[18:28:07] Eiam: cthulchu: there is a specific reason that :: works in that case but won't work in other cases, the link covers it.
[18:28:23] cthulchu: thanks, reading
[18:29:50] Eiam: I just think of it as " :: resolves scope, . calls methods".
[18:30:13] Eiam: even tho its possble to use :: to call a method in some cases. not a fan of that use case but its ruby, you do you.
[18:31:05] oncall-pokemon: has joined #ruby
[18:31:15] cthulchu: Eiam, in your link there's is an answer
[18:31:18] cthulchu: the first answer
[18:31:23] cthulchu: not the comment though
[18:31:25] pastorinni: has joined #ruby
[18:31:28] cthulchu: the first block of the code in it
[18:32:08] cthulchu: I just got this problem a few days ago
[18:32:13] cthulchu: I couldn't get the variable
[18:32:19] cthulchu: I had to use some awkward solution
[18:32:30] Eiam: is it because you are using :: ? =)
[18:32:41] cthulchu: no, I could've used ::
[18:32:52] cthulchu: instead I used some weird object method that got me the variable
[18:33:00] lbracher: has joined #ruby
[18:33:22] cthulchu: @selenium_wrapper.instance_variable_get("@driver")
[18:33:34] cthulchu: instead of @selenium_wrapper::driver
[18:33:42] cthulchu: probably would work as fine
[18:34:38] chat_: has joined #ruby
[18:35:49] jrich523: sounds like some confusion between static members on a class, and class instance (object)?
[18:36:01] Eiam: why in the world would they use instance_variable_Get
[18:36:04] Eiam: so weird
[18:36:26] Eiam: @selenium_wrapper.driver makes so much more sense =0
[18:36:31] herbmillerjr: has joined #ruby
[18:37:07] lbracher: Hi there! I did a gem update that says ruby version is 1.8, however, $(which ruby) -v gives me ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux] . Where is this ruby binary and how can I update it in my Ubuntu distro? Thanks in advance!
[18:37:09] Eiam: calling a method to access a variable thats already on your class just seems wonky and overly verbose
[18:37:29] Eiam: lbracher: whats the gem call you made thats telling you 1.8?
[18:37:32] Eiam: 1.8 has been EoL for a long time
[18:38:17] cthulchu: @selenium_wrapper.driver is not the ruby way
[18:38:18] lbracher: Eiam, gem update on a project directory
[18:38:28] Eiam: cthulchu: I'd completely beg to differ on that one
[18:38:35] cthulchu: I thied @selenium_wrapper.driver right away
[18:38:36] agent_white: has joined #ruby
[18:38:40] cthulchu: ment perfect sense to me
[18:38:45] cthulchu: you know what it said?
[18:38:50] cthulchu: there's no such method
[18:38:54] steerio: has joined #ruby
[18:39:21] cthulchu: so I googled and found that weird method of getting ivars
[18:39:27] steerio: hi all, I ran into the "bundler/dep_proxy" loaderror issue that should've been gone back in April
[18:39:27] cthulchu: I'm sure :: would've worked
[18:39:30] lbracher: Eiam, It says, for instance: Updating rack \n Fetching: rack-2.0.5.gem (100%) \n ERROR: Error installing rack: \n There are no versions of rack (= 2.0.5) compatible with your Ruby & RubyGems \n rack requires Ruby version >= 2.2.2. The current ruby version is 1.8.
[18:39:38] cthulchu: even in your example, they claim . doesn't work
[18:39:41] steerio: anyone here knows how it can occur with 2.5.0, latest rubygems, latest bundler?
[18:39:51] cthulchu: Example::Version # => 1.0
[18:39:52] cthulchu: Example.Version # NoMethodError
[18:40:06] Eiam: cthulchu: because they didn't create accessors
[18:40:23] cthulchu: how do you create accessors?
[18:40:24] Eiam: attr_accessor :driver
[18:40:42] cthulchu: interesting
[18:40:52] cthulchu: okay, later about that
[18:40:58] cthulchu: time to make mistakes :)
[18:41:21] jrich523: thank goodness for git lol
[18:41:36] Eiam: cthulchu: so the driver variable is being "hidden" as it has no exposed accessors (like getters/setters)
[18:41:48] Eiam: but its still there, but "getting" to it requires the instance_variable_get to "get" it
[18:41:52] cthulchu: would I be able to still access it via ::?
[18:42:12] cthulchu: so this instance_variable_get is a cheat, basically
[18:42:28] cthulchu: if the language was stricter, I wouldn't've accessed the var from outside?
[18:42:41] cthulchu: it's like private when there's no accessors?
[18:42:54] cthulchu: weird cuz I would expect for it to be public by default
[18:43:12] Eiam: instance_variable_get may be how its implemented under the covers, but to me yes, using instance_variable_get is a kind of "cheat". I'm not the authority, and the method does what you want so w/e
[18:43:27] Eiam: if they wanted you to access and use it, they should have added class accessors
[18:43:35] Eiam: if they wanted read only, attr_reader :driver
[18:43:44] cthulchu: why aren't the vars accessible by default?
[18:43:49] banisterfiend: has joined #ruby
[18:44:02] Eiam: design decision? thats just how classes work by default
[18:44:08] cthulchu: the opposite makes more sense: add protectors if you don't want the var to be accessed
[18:44:24] cthulchu: it's good to know
[18:45:02] cthulchu: ha! :: omits the accessors too!
[18:45:05] Eiam: there is attr_reader, attr_writer and attr_accessor which define read, write and both respectively
[18:45:11] jrich523: meh, from a security point of view, private by default
[18:45:34] cthulchu: ruby is not an exactly strict language
[18:45:42] cthulchu: not about security
[18:45:49] Eiam: just feel the vibes man
[18:45:50] Eiam: chill dude
[18:45:54] Eiam: thats Ruby to me. =)
[18:46:05] lbracher: How can I update ruby installation that gems is using?
[18:46:05] cthulchu: I totally agree. it feels relaxing
[18:46:16] jrich523: the ambiguity drives me nuts
[18:46:26] Eiam: lbracher: are you using bundler?
[18:46:29] cthulchu: embrace it :)
[18:46:36] jrich523: lol it makes it super hard to read
[18:46:38] Eiam: jrich523: I just define my own rules within my code
[18:46:47] Eiam: and just enforce those rules for said code base. sanity
[18:46:54] jrich523: yeah i usually have to work on other people stuff
[18:47:01] Eiam: ages ago, my old boss set those rules and I hated working with his ruby
[18:47:04] Eiam: reading it droves me fucking nuts
[18:47:06] lbracher: Eiam, no. I'll install it and I'll tell you if it works or not. :)
[18:47:11] Eiam: method_missing all over the place
[18:47:45] jrich523: there are too many little rules to remember
[18:47:58] cconstantine: has joined #ruby
[18:48:20] jrich523: dont need x if you do y but if you do it this way then you also dont need to do Z
[18:48:40] jrich523: for the love of god, slapping some () or {} around things isnt the end of the world, just stick to standards
[18:49:33] jrich523: standards is a bad choice of word.... norms
[18:49:48] eam: normies
[18:50:39] cconstantine: Hello! I’m trying to write a proxy server in ruby. I’d like to be able to accept incoming tls connections, parse out the hostname indiciated in SNI, then proxy the TCP connection. (much like fabio’s tcp-sni mode: https://fabiolb.net/feature/tcp-sni-proxy/ ). Is there a library that would let me do this easily?
[18:53:05] ellcs: has joined #ruby
[18:53:09] za1b1tsu: has joined #ruby
[18:53:18] cthulchu: I have something that looks like a sacrilege.
[18:53:26] cthulchu: require 'require_all'
[18:53:28] wontruefree: has joined #ruby
[18:54:02] cthulchu: looks scary
[18:54:28] jrich523: i have some really crazy stuff in my current project.. which i guess i'll try to tackle at some point.. but... im way lost on why its that way
[18:54:56] cthulchu: It's just I was using requires as my main way to study what does what in this codebase. and now this...
[18:54:58] jrich523: in the gem file it points back to the product to include itself.. which i think was so the main bin file could access it as a library? not really sure... mad weird
[18:55:15] tty: has joined #ruby
[18:56:37] cthulchu: oh wonderful.
[18:56:50] cthulchu: now I see this: require_rel '../../lib/*.rb'
[18:57:23] jrich523: so in this project, in the lib he has a folder (basically the module)
[18:57:38] jrich523: which at its root is just a bunch of requires (single module in multiple files)
[18:57:52] jrich523: which i guess is kinda nice, except for the gemfile part
[18:58:19] cthulchu: I mean, it defeats the purpose of including only what you use
[18:58:24] cthulchu: but again, it's ruby
[18:58:28] cthulchu: so just chill
[18:58:37] wontruefree: has joined #ruby
[18:58:40] jrich523: another beef i have, is that when you import you dont (cant?) define what it is you get
[18:58:44] jrich523: like python/node you'll do
[18:58:47] jrich523: import x from lib
[18:58:52] jrich523: and you know, x is from that library
[18:59:14] jrich523: i had some product library that exposed "Client" and it took some hair pulling to figure out that was from a require
[19:01:00] Eiam: jrich523: you could define modules, then include the modules inside a class
[19:01:06] Eiam: to try and constrain what you get
[19:01:41] jrich523: sure, but im not the one creating this stuff... im usually given some pile of code, told to figure it out and add a feature
[19:01:58] jrich523: and usually its older code that is no longer owned by anyone, which is why they brought me in...
[19:02:21] jrich523: "figure it out.. have fun... lol"
[19:02:26] jrich523: sums up my life
[19:02:53] Eiam: thats how you learn
[19:02:53] Kundun: has joined #ruby
[19:02:57] Eiam: sorting out other peoples messes
[19:03:06] Eiam: include if that other person is you from 5 days ago
[19:03:07] jrich523: oh for sure, its frustrating, but i like my job
[19:03:12] aufi: has joined #ruby
[19:03:28] jrich523: its not language limited either... and im very happy to learn ruby.. just... its def one of the more painful langs to pick up
[19:03:37] jrich523: cuz of all the rules/exceptions
[19:03:38] Eiam: thats how I learned rails, and sproutcore
[19:03:47] jottr: has joined #ruby
[19:03:53] Eiam: eh, it will come together. I remember that too, being frustrated by all the different ways
[19:04:01] jrich523: i just dont see the point
[19:04:03] Eiam: you'll get most the common cases figured out soon enough
[19:04:11] Eiam: freedom of expression? its part of the language
[19:04:17] mikecmpbll: most peoples' experience is that ruby is one of the least painful to pick up.
[19:04:24] Eiam: if you want forced opinions, check out Python
[19:04:28] jrich523: i guess i dont think you should be given that freedom, this isnt an art class :)
[19:04:46] mikecmpbll: i'm not just randomly asserting that, based on everyone i've ever recruited.
[19:04:54] jrich523: mikecmpbll as an addional lang, or to learn programming/scripting?
[19:04:56] mikecmpbll: mostly graduates who learned in java/c#
[19:05:00] jrich523: those are two way different problems :)
[19:05:05] Eiam: mikecmpbll: I'd say it was the most fun to pick up, certainly =)
[19:05:26] mikecmpbll: jrich523 : as an additional lang.
[19:05:27] Eiam: I do recal frustration at the breadth of how people do things but, no more irritating than I am when I write javascript
[19:05:49] jrich523: i guess its less frustrating than... i'll call it node (modern javascript?)
[19:06:17] Eiam: jrich523: if you really want to be told how to do things, you could try out haskell? =)
[19:06:17] jrich523: i'll likely master ruby way before i get a grasp on the current world of JS
[19:06:37] jrich523: i dont pick it, im told
[19:06:57] jrich523: usually to work on a product, in this case its foreman/puppet so ruby
[19:07:03] jrich523: was doing jenkins work before in GO
[19:07:19] jrich523: did ptyhon with ansible/openstack prior to that
[19:07:35] jrich523: before that was an SRM like product in powershell
[19:07:39] lbracher: Eiam, I got "Could not verify the SSL certificate for https://rubygems.org/quick/Marshal.4.8/pg-0.7.9.2008.01.28.gemspec.rz" while performing a `bundle update`. I tried `sudo gem update --system` to solve it but I got the same error. Any ideas?
[19:07:45] jrich523: so... i dont really get to pick very often
[19:08:11] Eiam: lbracher: no, I'm not very good at de-tangling that part of ruby, sorry
[19:08:30] lbracher: Eiam, ok! Thanks! ;)
[19:08:51] mikecmpbll: lbracher : do you use rvm?
[19:09:05] jrich523: weird that the ssl cert from rubygems.org would cause an issue?
[19:12:57] Nicmavr: has joined #ruby
[19:13:34] lbracher: mikecmpbll, to be honest, today is my first day with Ruby I know nothing about the ecosystem and I'm a little bit confused. To make a long story short, I'm trying to fix a rails system for a friend and I figured out Apache doesn't load because command PassengerDefaultRuby on apache2.conf file. My friend told me it was working before. Maybe it's just a Gemfile problem and I'm blowing neurons for nothing?
[19:13:48] Guest59508: has joined #ruby
[19:14:02] mikecmpbll: sounds like almost nothing to do with ruby itself :)
[19:14:31] dinfuehr: has joined #ruby
[19:15:02] mikecmpbll: can't really help without the error. presumably it's a passenger spawning error
[19:17:59] lbracher: mikecmpbll, I'm totally lost with that error. It says "Invalid command 'PassengerDefaultRuby', perhaps misspelled or defined by a module not included in the server configuration" when I `sudo /etc/init.d/apache2 start`
[19:19:32] mikecmpbll: i'm not particularly familiar with apache, i use nginx. however, that's the correct name for the directive; maybe passenger isn't installed correctly, or you're using the directive in the wrong context?
[19:19:58] mikecmpbll: check your apache virtualhost config and the docs: https://www.phusionpassenger.com/library/config/apache/reference/#passengerdefaultruby
[19:20:15] cthulchu: initialize methods are, basically, constructors?
[19:20:22] cthulchu: and we can have many initialize methods with different signatures?
[19:20:36] lbracher: mikecmpbll, I'll try it. Thank you! :)
[19:20:56] mikecmpbll: cthulchu : yes, and no.
[19:21:14] cthulchu: or since we're typeless and since we can do and we can do initialize(a=0)
[19:21:22] mikecmpbll: ruby doesn't have the concept of method overloading.
[19:21:23] cthulchu: we can fit all signatures in one
[19:21:41] cthulchu: fells very relaxing
[19:24:21] jrabe: has left #ruby: ()
[19:26:56] jrabe: has joined #ruby
[19:30:45] Eiam: cthulchu: also a ruby method can end its argument list with a hash
[19:31:01] cthulchu: I don't see when I would need it
[19:31:08] cthulchu: never ever needed it
[19:31:14] Eiam: hah. its used a ton, everywhere
[19:31:48] cthulchu: yeah, why bother thinking and planning your structure if you can change it whenever you want
[19:32:01] cthulchu: is this the most relaxed language in the universe?
[19:32:11] Eiam: often in lieu of even bothering with naming parameters directly
[19:32:26] Eiam: def method(). pass a hash into it, presto named arguments
[19:33:06] cthulchu: so method() is a constructor of a method that belongs to the object class?
[19:33:42] Puffball: has joined #ruby
[19:34:19] Eiam: you mean the actual method and not an example?
[19:34:25] za1b1tsu: has joined #ruby
[19:34:30] Eiam: https://ruby-doc.org/core-2.2.0/Method.html
[19:34:46] cthulchu: I thought your example was the actual code
[19:35:01] cthulchu: oh, you defined it
[19:35:02] AJA4350: has joined #ruby
[19:35:02] Eiam: nah i was using it as an example to just define a method and later you can sort out what you pass into it
[19:35:21] Eiam: but it works like you said too if you think of it as Method the thing and not method the generic example =0
[19:35:40] clemens31: has joined #ruby
[19:35:55] cthulchu: okay, good to know
[19:36:16] orbyt_: has joined #ruby
[19:39:29] dbugger__: has joined #ruby
[19:40:18] lucasr: has joined #ruby
[19:41:57] amelliaa: has joined #ruby
[19:45:26] Paraxial: has joined #ruby
[19:45:31] cthulchu: and there's no difference between .new and .new()?
[19:48:01] jrich523: () are optional :)
[19:48:08] jrich523: and a ton of other things lol
[19:48:29] workmad3: has joined #ruby
[19:48:31] jrich523: so .new value and .new(value) are the same thing
[19:48:50] jenrzzz: has joined #ruby
[19:48:57] jrich523: bout 50 ways to enter in named params too lol
[19:49:08] ellcs: has joined #ruby
[19:49:31] cthulchu: doesn't it cause issues when minify?
[19:49:59] cthulchu: anyhow, gonna just use it :)
[19:50:35] jrich523: there is a minify? that sounds really really scary
[19:51:10] jrich523: any AST for ruby?
[19:51:20] jrich523: that would make that more reasonable i guess?
[19:51:23] lucasr: has joined #ruby
[19:54:44] jrich523: lol im trying to follow rubocop's rules.. just gave me crap about a word array, googled it.. syntax shown was %w().. use that... and now rubocop is like hey you should do %w[]...
[19:55:54] eam: rubocop is often wrong
[19:56:02] jrich523: its way more right than i am :)
[19:56:11] eam: not me! :D
[19:56:44] jrich523: how do i inject you in to my VS Code? :)
[19:57:27] jrich523: they did add a shared/remote view thing.. have yet to try it...
[19:57:44] jrich523: 'live share' thats what it is
[19:58:21] ciscam: has joined #ruby
[20:02:22] chouhoulis: has joined #ruby
[20:02:41] cthulchu: oh so the variables actually have types
[20:02:45] cthulchu: they're just implicit
[20:02:53] cthulchu: and quite hard types too
[20:03:00] cthulchu: a variable can't mutate its type?
[20:03:14] cthulchu: so I can't do a = nil and then a = "pew-pew"
[20:03:21] wald0: has joined #ruby
[20:03:42] cthulchu: I'd expect it
[20:05:47] orbyt_: has joined #ruby
[20:08:35] quobo: has joined #ruby
[20:12:20] cconstantine: has joined #ruby
[20:12:25] wontruefree: has joined #ruby
[20:15:22] mikecmpbll: rubocop isn't "right", OR "wrong". it's does what you tell it.
[20:15:41] mikecmpbll: cthulchu : yes, you can redefine variables.
[20:15:51] icarus: has joined #ruby
[20:18:44] eam: mikecmpbll: the defaults :D
[20:19:22] mikecmpbll: rubocop without defaults would be a pain to use.
[20:19:50] jrich523: it wouldnt be used :)
[20:19:52] mikecmpbll: doesn't mean you have to submit to defaults like some syntax-submissive.
[20:20:23] jrich523: well in my case, i assume its better than my garbage, and in most cases it is
[20:20:39] jrich523: however, this line it had me craft is driving me nutty and im likely to change it back to my crappy way
[20:20:45] jrich523: kvms = kvms.select { |h| options[:site].casecmp(h['site']).zero? } if options[:site]
[20:21:04] nicht: has joined #ruby
[20:21:07] jrich523: after like 4 revisions of its suggestions, i ended up with that.. and i dont like it one bit lol
[20:21:11] eam: syntax submissive I like it
[20:21:25] chouhoulis: has joined #ruby
[20:21:30] eam: just saying the defaults are silly and overly pedantic with bad opinions. of course they can be changed
[20:22:16] eam: but we can, and should, still criticize the choices of defaults ;)
[20:23:02] eam: if they were less opinionated we might be able to establish a widely agreed upon common subset!
[20:23:21] jrich523: isnt that the problem with ruby?
[20:23:22] mikecmpbll: sure, doesn't detract from the fact that rubocop is brilliant OSS.
[20:23:24] mikecmpbll: you can't have a styleguide without being opinionated.
[20:23:25] mikecmpbll: just change your settings.
[20:23:30] eam: you can
[20:23:30] jrich523: i mean, when yuou have a million ways to do something, no one will ever agree
[20:23:35] mikecmpbll: no, you cannot.
[20:23:43] eam: of course you can, don't be silly
[20:24:10] mikecmpbll: are you just going to repeat yourself or explain how you can decide what's the right way without being opinionated?
[20:24:12] eam: rubocop could omit a warn about %w characters, or allow a larger set, or ...
[20:24:14] jrich523: you are both correct :)
[20:24:31] mikecmpbll: ___you can set rubocop not to warn about that___
[20:24:44] eam: yes, but we are discussing the defaults, did you forgeT?
[20:24:53] eam: I think you might be getting lost here
[20:25:04] mikecmpbll: i'm not lost, i've already stated why there are defaults.
[20:25:13] mikecmpbll: [21:19:09] <mikecmpbll> rubocop without defaults would be a pain to use.
[20:25:23] eam: the defaults are poor, are too opinionated. "too" opinionated is not the same as "not having opinions at all"
[20:25:38] mikecmpbll: installing rubocop and have no immediate effect would be fucking stupid.
[20:25:39] eam: you are swinging between absolutes
[20:25:47] eam: no one is suggesting those things
[20:25:48] eam: calm down
[20:25:54] mikecmpbll: because the middleground between those absolutes is called "opinion"
[20:26:00] mikecmpbll: you disagree with opinion
[20:26:09] eam: and the criticism is that there is too much opinion
[20:26:12] eam: here check this out
[20:26:20] eam: we live in a beautiful world full of color
[20:26:34] eam: try to see past the two black and white tones you're currently considering
[20:27:00] eam: it is possible for something to be "less opinionated" without having no opinion whatsoever
[20:27:22] mikecmpbll: how can you grade an amount of opinion?
[20:27:24] mikecmpbll: either you make a decision about something, i.e. should we have spaces before {} or not?
[20:27:25] mikecmpbll: or you choose not to have an opinion on it
[20:27:29] mikecmpbll: you can't have half an opinion
[20:27:29] eam: I literally just did
[20:27:39] eam: and I even gave you a specific example
[20:28:07] kmurphy4: has joined #ruby
[20:28:14] jrich523: you're both right (or wrong)
[20:28:17] mikecmpbll: ah, so you think they should make fewer decisions? so they should have a default about spaces before braces, but not about %w[] vs %w()?
[20:28:22] mikecmpbll: i understand you now
[20:28:34] mikecmpbll: i really don't see what additional value that provides
[20:28:43] mikecmpbll: it just means more people don't realise there's a cop for %w() vs %w[]
[20:29:03] eam: 20:23 < eam> if they were less opinionated we might be able to establish a widely agreed upon common subset!
[20:29:03] mikecmpbll: and fewer projects have a comprehensive style guide.
[20:29:18] mikecmpbll: i don't understand how fewer opinions can result in more agreement?
[20:29:35] jrich523: fewer differing opinions
[20:29:43] mikecmpbll: so more indecision?
[20:29:50] cconstantine: has joined #ruby
[20:29:52] jrich523: hmm more decision?
[20:30:08] eam: have you ever used perltidy? The tool rubocop was patterened after?
[20:30:08] mikecmpbll: more decision is more opinion.
[20:30:08] jrich523: room of 10 people... "everyone pick the best color" 8 people pick green
[20:30:12] jrich523: screw the other two
[20:30:31] jrich523: we decided, two other people have a differing opinion, but who cares, its a small % of the group
[20:30:39] eam: that's an example of a more reasonable set of defaults
[20:30:53] mikecmpbll: eam : how so?
[20:30:54] jrich523: which is what this set of defaults SHOULD be
[20:31:02] jrich523: i have no idea if they are, cuz im new to ruby :)
[20:31:05] eam: it has a *ton* of rules which aren't on at default levels
[20:31:50] eam: rubocop is (afaik) missing the concept of severity/opinion levels entirely
[20:32:04] eam: perltidy at the highest level is kinda dumb, most folks don't agree with it
[20:32:15] eam: but almost everyone agrees with the lower level stuff
[20:32:56] mikecmpbll: what do you mean at the highest level?
[20:33:33] BTRE: has joined #ruby
[20:34:10] cconstantine: has joined #ruby
[20:34:24] banisterfiend: has joined #ruby
[20:35:04] jrich523: the more obscure sugestions im guessing
[20:35:13] jrich523: like only 10% of the rules are agreed upon as "must"
[20:35:20] jrich523: but the default rule set has 15% of them
[20:35:33] jrich523: 5% that eam thinks (and many others?) a bit much for the default set
[20:37:09] mikecmpbll: can debate ad-infinitum about defaults, it's pretty fucking inconsequential—just configure it how you want.
[20:38:25] jrich523: its very consequential for people me... i use it as a guide to "good ruby"
[20:38:34] mikecmpbll: then follow it?
[20:38:37] jrich523: but, not something that will be chaned here :)
[20:38:43] jrich523: and i'll learn better at some point
[20:38:45] mikecmpbll: either it's a good guide and you follow it, or it's not and you don't.
[20:38:46] jrich523: but its a good starting point
[20:38:55] mikecmpbll: they're both as easy as the other.
[20:39:09] jrich523: both? use or not use? clearly its easier to use :)
[20:39:30] jrich523: otherwise i have to paste my lines here and be like "how do i make this pile of crap more ruby like"
[20:39:38] jrich523: and ya'll will get sick of that real quick :)
[20:41:50] cconstantine: has joined #ruby
[20:42:42] eam: mikecmpbll: sorry, meeting - I meant perlcritic btw, not perltidy
[20:42:53] eam: it has a concept of severity, ranging from 1 to 5
[20:43:09] jottr: has joined #ruby
[20:43:25] eam: severity 5 is stuff that is almost certainly an error, or will be actively dangerous
[20:43:36] eam: as you move towards 1 you go more towards subjective opinion
[20:44:22] mikecmpbll: sounds like a worthless abstraction. the project maintainer can decide what's right or wrong for that project, what's the need for a ranking once you've chosen your path?
[20:44:49] mikecmpbll: merge request comes in, it has five level 1 failures, they're not severe so do you merge it?
[20:44:51] eam: it's pretty important, because some things are almost certainly errors that a linter should catch (eg, assignment in what appears to be a test)
[20:45:10] eam: the default is level 5
[20:45:24] eam: the default is almost certainly indicative of a real problem, a real error
[20:45:35] mikecmpbll: why would anything be merged with issues though? what's the point of the grading?
[20:45:46] eam: then there are increasingly pedantic and opinionated sets of criticisms which you can use if you like
[20:46:26] eam: because the authors recognize the gradient of subjective opinion
[20:46:33] eam: iirc we ran most of our projects on level 3 or so
[20:46:37] eam: with a set of additional critics
[20:46:48] eam: 4/5 were too opinionated
[20:47:22] mikecmpbll: so ultimately the project maintainer chooses a level; practically no different from configuring rubocop
[20:47:23] pastorinni: has joined #ruby
[20:47:24] eam: rubocop, by default, makes it hard to distinguish between important syntax problems and silly ones
[20:47:36] eam: again, we are discussing useful defaults
[20:47:52] mikecmpbll: no we're not, because you said the maintainer chooses a level
[20:47:57] mikecmpbll: that's not a default, that's a choice.
[20:48:01] ur5us: has joined #ruby
[20:48:02] eam: no, I did not say that
[20:48:08] eam: and that isn't how it works
[20:48:12] eam: the default is the lowest level
[20:48:19] cthulchu: do I have a console here?
[20:48:23] mikecmpbll: [21:45:46] <eam> then there are increasingly pedantic and opinionated sets of criticisms which __you can use if you like__
[20:48:39] eam: are you struggling to understand what a default is? is that the issue here?
[20:48:53] eam: then I'm not sure why we're having trouble communicating
[20:49:32] eam: I wish rubocop had more sensible defaults
[20:49:32] eam: that's it!
[20:49:34] cthulchu: n> puts test
[20:49:34] cthulchu: >> puts test
[20:49:48] ruby[bot]: cthulchu: # => wrong number of arguments (given 0, expected 2..3) (ArgumentError) ...check link for more (https://eval.in/1020120)
[20:50:17] eam: the ranking of severity is also useful, I think, because it indicates to a newbie whether the style is a pure style issue or a possible serious mistake
[20:50:23] jcarl43: has joined #ruby
[20:51:36] Lytol: has joined #ruby
[20:52:31] mikecmpbll: the "lint" cops in rubocop are for syntax and code errors, you can easily just run those on their own
[20:54:26] ciscam: has joined #ruby
[20:55:16] headius: has joined #ruby
[20:57:53] cthulchu: looks like << is A LOT more performant than +
[20:58:44] cthulchu: https://stackoverflow.com/questions/377768/string-concatenation-in-ruby?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
[20:59:13] jenrzzz: has joined #ruby
[20:59:14] jenrzzz: has joined #ruby
[21:00:31] tekk: has joined #ruby
[21:05:09] cconstantine: has joined #ruby
[21:05:50] ur5us: has joined #ruby
[21:10:06] intheclouddan: has joined #ruby
[21:10:30] banisterfiend: has joined #ruby
[21:10:52] chat: has joined #ruby
[21:14:00] jenrzzz: has joined #ruby
[21:14:06] jenrzzz: has joined #ruby
[21:18:57] ramfjord: has joined #ruby
[21:22:31] za1b1tsu: has joined #ruby
[21:42:37] jrich523: hey guys... so im trying to filter my array of hashes..
[21:43:02] orbyt_: has joined #ruby
[21:43:02] jrich523: and im getting an error about nil, but im certain this field has a value in all instnaces (i printed it out without the filter)
[21:43:34] jrich523: kvms = kvms.select { |h| options[:site].casecmp(h['site']).zero? } unless options[:site].nil? thats the dirty bit of code i came up with (mostly rubocopy)
[21:44:02] jrich523: but its basically saying that the h['site'] is nil, which makes me feel like im doing something wrong, cuz it shouldnt have any nil values
[21:44:22] baweaver: "shouldn't" is a very dangerous word
[21:44:34] jrich523: well, im as sure as i can be
[21:44:39] baweaver: Always verify
[21:44:44] jrich523: i ran an arr.each with puts
[21:44:48] jrich523: no empty "site" values
[21:45:00] jrich523: so, to that end, im sure
[21:45:06] baweaver: If your interpreter said there's a nil...
[21:45:10] jrich523: i dont know ruby enough to know if there is some black magic im missing :)
[21:45:25] baweaver: That's the thing, there's really not that much magic.
[21:45:27] apeiros: you could also have misread the exception
[21:45:44] jrich523: i wrote it both ways (H to opions, options to h)
[21:45:55] jrich523: to identify that its really angry about the h['site'] being nil
[21:46:02] apeiros: anyway, you can try to reduce kvm's values to a small set which still causes the error
[21:46:03] jrich523: cant find a method, vs cant compare to nil
[21:46:16] apeiros: and when you have that, paste it
[21:46:26] jrich523: im not sure i follow you?
[21:46:51] apeiros: how many items are in kvms?
[21:47:28] apeiros: run it for 50, see if it crashes. if not, run it for the other 50
[21:47:40] apeiros: then in the crashing half, run it for 25, etc.
[21:47:48] jrich523: basically, tease out which record is causing the issue?
[21:47:56] apeiros: alternatively:
[21:47:56] baweaver: you sure about that being a string key?
[21:47:58] baweaver: options[:site] and h['site']
[21:48:09] apeiros: have a begin/rescue with binding.pry inside your select
[21:48:38] baweaver: If it says no method for nil, it means the left side is nil. Can't compare to nil means something on the right side of casecmp.
[21:49:00] baweaver: short version: there's a nil.
[21:49:04] jrich523: options[:site] is the param passed in (optparser) so --site abc
[21:49:13] workmad3: has joined #ruby
[21:49:22] jrich523: ok, i guess mostly i wanted to make sure that in some weird way my H wasnt something else or wrong
[21:49:42] fmcgeough: has joined #ruby
[21:49:44] jrich523: i'll start to rip apart the data
[21:49:58] apeiros: btw., `unless options[:site].nil?` --> `if options[:site]`
[21:50:21] jrich523: yeah should have changed that before i posted it..
[21:51:03] jottr: has joined #ruby
[21:52:49] jrich523: im doing something horribly wrong
[21:53:00] cthulchu: will it tolerate if I pass arguments in a method/function that don't expect arguments?
[21:53:03] cthulchu: is it that good?
[21:53:08] cthulchu: to idnore them
[21:53:21] jrich523: oh come on now, thats something you should try
[21:53:22] cthulchu: you're corrupting me
[21:53:25] jrich523: dont forget to report back, im curious :)
[21:53:41] cthulchu: can I do it here with the >>?
[21:53:49] cthulchu: I'm not good enough with my ruby instance
[21:54:11] jrich523: so... i tried this...
[21:54:18] jrich523: kvms.each_index {|x| puts "#{x} -#{kvms[x]['site']}-" }
[21:54:21] cthulchu: >> def a(){} a(1,2,3)
[21:54:22] ruby[bot]: cthulchu: # => /tmp/execpad-487594caa717/source-487594caa717:2: syntax error, unexpected tIDENTIFIER, expecting key ...check link for more (https://eval.in/1020158)
[21:54:24] jrich523: and i get -- (all nil, wtf?)
[21:54:33] jrich523: that answers that one :)
[21:54:39] baweaver: cthulchu: Try it locally first.
[21:54:52] cthulchu: I kinda can't
[21:54:58] jrich523: i use the site in another puts ok, (let me trim it down)
[21:55:14] cthulchu: I don't feel familiar enough with it
[21:55:25] baweaver: Just use irb.
[21:55:36] cthulchu: but what I did here, did I do it right?
[21:55:39] jrich523: kvms.each do |k| puts ' %<site>s ' % k end
[21:55:44] jrich523: that will use my site ok
[21:56:14] cthulchu: how do we do >> here?
[21:57:26] cthulchu: how does irb work?
[21:57:36] jrich523: what do you mean?
[21:57:50] cthulchu: https://i.imgur.com/LDBHQIP.png
[21:58:20] cthulchu: how do I get the output though
[21:58:27] jrich523: it should echo by default
[21:58:33] jrich523: which happens to be super annoying lol
[21:58:52] jrich523: start simple: 1+ 2
[21:59:02] jrich523: it will echo the result
[21:59:04] cthulchu: this is weird
[21:59:17] cthulchu: https://i.imgur.com/RUuyKKP.png
[21:59:19] zenspider: has joined #ruby
[21:59:20] jrich523: still echo's (sort of annoying, you can disable it)
[21:59:34] cthulchu: it doesn't work
[21:59:37] jrich523: see the ? on line 2
[21:59:41] jrich523: thats a sub command i think
[21:59:46] jrich523: sorta like a missing }
[21:59:49] cthulchu: okay, I'm done with it
[21:59:53] kmurphy4: has joined #ruby
[22:00:00] cthulchu: I don't have missing }
[22:00:03] jrich523: also you rammed too much on a line
[22:00:08] gravitation: has joined #ruby
[22:00:09] jrich523: you have a missing ;
[22:00:10] jrich523: or a new line :)
[22:00:16] jrich523: just guessing anyways
[22:00:18] cthulchu: that makes sense
[22:00:23] jrich523: you joined up the def and use
[22:00:36] jrich523: so to use it here, it might work if you toss a ; between the def/call
[22:00:46] karapetyan: has joined #ruby
[22:00:56] gravitation: has joined #ruby
[22:01:04] nfk: has joined #ruby
[22:01:14] cthulchu: https://i.imgur.com/CkvtpU3.png
[22:01:39] cthulchu: baweaver, how do you use irb?
[22:01:43] cthulchu: feels like vim
[22:01:45] gravitation: has joined #ruby
[22:01:46] jrich523: mine is a tad different (more obvious maybe?)
[22:01:57] Mia: has joined #ruby
[22:01:57] Mia: has joined #ruby
[22:02:06] apeiros: cthulchu: def a(){} isn't really something
[22:02:07] jrich523: https://snag.gy/2ORcYN.jpg
[22:02:10] baweaver: I'd almost suggest reading a Ruby book by this point.
[22:02:22] cthulchu: if it's not something, I expect a syntax error
[22:02:30] cthulchu: ah, it's like literally nothing
[22:02:31] gravitation: has joined #ruby
[22:02:33] apeiros: it's in some kind of continuation mode where it expects more input to complete an expression
[22:02:38] cthulchu: so the output is empty
[22:02:51] apeiros: type "end" and you get your syntax error ;-)
[22:02:58] cthulchu: I don't need end
[22:03:05] cthulchu: isn't it the same?
[22:03:32] apeiros: with blocks, you can use {} or do/end
[22:03:37] apeiros: but even there it's not the same.
[22:03:45] apeiros: but you can't with method defs.
[22:03:48] jrich523: lol love me some ruby
[22:03:52] apeiros: there's no `do` in a method def.
[22:03:55] agent_white: has joined #ruby
[22:04:00] cthulchu: so I can't do it with deeefs
[22:04:03] cthulchu: now it makes sense
[22:04:04] Azure: has joined #ruby
[22:04:24] cthulchu: okay, so it's not possible to do what I want in one line
[22:04:25] apeiros: cthulchu: btw., change the prompt to show nesting level
[22:04:28] cthulchu: not gonna do it then
[22:04:35] cthulchu: it shows me the nesting level
[22:04:37] apeiros: jrich523 apparently has set theirs
[22:04:38] TinkerT: has joined #ruby
[22:04:40] cthulchu: using spaces
[22:04:50] jrich523: i did not, was default
[22:04:57] jrich523: only thing i screwed with was the echo
[22:05:12] apeiros: jrich523: well, your last number is the nesting level
[22:05:25] jrich523: figured that out the hardway already :)
[22:05:27] jrich523: super helpful tho
[22:05:28] apeiros: shows that you're 1 level nested and hence your expression is not completed
[22:05:47] jrich523: however, back to the topic of {} / do/end
[22:05:47] apeiros: anyway, IMO use pry anyway.
[22:05:53] cthulchu: okay, dolks, could you please test it quickly for me?
[22:05:54] jrich523: shouldnt mine be ok?
[22:06:01] cthulchu: I have real issues with irb
[22:06:15] apeiros: jrich523: in your jpg?
[22:06:16] jrich523: check out pry
[22:06:31] jrich523: yeah, the def a { puts "ran" }
[22:06:33] apeiros: 00:03 apeiros: there's no `do` in a method def.
[22:06:34] jrich523: why is it continued?
[22:06:44] cthulchu: cuz you can't use {} with def
[22:06:46] jrich523: but the {} vs do/end
[22:06:46] cthulchu: we explained it
[22:06:54] cthulchu: you don't have do in def
[22:06:57] cthulchu: there's no {
[22:07:05] jrich523: so its not either, its only do/end?
[22:07:08] apeiros: jrich523: I have no idea what irb sees to be continued
[22:07:19] cthulchu: it's only def/end when it's def
[22:07:25] cthulchu: you can use {} when it's do/end
[22:07:34] cthulchu: from what I understood
[22:07:40] TinkerT: has joined #ruby
[22:07:50] apeiros: cthulchu: yes, and do/end is only with blocks :)
[22:07:52] cthulchu: I wonder if I still need new lines when doing def/end
[22:08:05] cthulchu: I consider def/end a block
[22:08:08] jrich523: irb wanted it... got grumpy at me
[22:08:18] apeiros: >> def foo(x) x+2 end; foo(1) # no newline needed, not even ;
[22:08:19] ruby[bot]: apeiros: # => 3 (https://eval.in/1020161)
[22:08:32] cthulchu: not even ;?!
[22:08:50] apeiros: in a couple of cases when it's unambiguous
[22:08:57] moei: has joined #ruby
[22:09:07] cthulchu: >> def a() true end; a(1)
[22:09:07] ruby[bot]: cthulchu: # => wrong number of arguments (given 1, expected 0) (ArgumentError) ...check link for more (https://eval.in/1020162)
[22:09:14] cthulchu: impossible!
[22:09:19] cthulchu: signatures are real!
[22:09:39] cthulchu: you can pass less, but don't you dare to pass more!!!
[22:10:23] jrich523: damn it... i think i know what my issue was :-/
[22:11:05] jrich523: btw, pry is suppose to be a lot better than irb
[22:11:12] cthulchu: JS allows it!
[22:11:14] jrich523: which i would be using, except its not very friendly with bundler
[22:11:42] apeiros: in what way is pry not bundler-friendly?
[22:12:03] jrich523: let me grab the error
[22:12:18] jrich523: i have a gem i have to work in, so to work in it i've had to do: bundle exec ruby /bin/blah
[22:12:32] jrich523: so i replace that with irb to get all the local gem dependencies
[22:12:40] cthulchu: Ruby is not as hippy and goofy as it seems. It pretends!
[22:12:42] jrich523: bundle exec ruby irb
[22:12:49] jrich523: which will let me require whatever is in this gem
[22:12:55] jrich523: pry gave an error, let me try it again
[22:13:23] apeiros: you mean `bundle exec irb`, yes?
[22:13:27] jrich523: oh, it cant find it, but if i use just pry on the cmdline it works
[22:13:27] amar: has joined #ruby
[22:13:38] jrich523: so yeah, same thing.. sorta...
[22:14:04] apeiros: did you do `bundle exec ruby pry`? if so, that's wrong.
[22:14:35] jrich523: bundler/rubygems_integration.rb:458:in `block in replace_bin_path': can't find executable pry for gem pry. pry is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)
[22:14:44] jrich523: a "better" error without the `ruby`
[22:15:03] apeiros: tells you straight what I forgot to do
[22:15:11] apeiros: you apparently didn't list pry in your gemfile.
[22:15:22] jrich523: well, i wouldnt actually want it in there
[22:15:36] jrich523: i mean, yes i can screw with it to get it working
[22:15:38] apeiros: what's not in the gemfile can't be used with bundler
[22:15:46] apeiros: that's… like… the point of bundler.
[22:15:52] jrich523: irb can just fine it seems
[22:16:03] jrich523: but irb is an executable im guessing? vs a gem?
[22:16:06] apeiros: because irb isn't a gem.
[22:16:12] jrich523: i figured thats what hte issue was
[22:16:16] jrich523: just didnt really bother to find a fix
[22:16:29] jrich523: since it didnt seem to offer THAT much
[22:16:55] apeiros: if you develop a gem, what you do is you add pry as a development dependency
[22:17:04] apeiros: and in your gemfile, you reference the gemspec
[22:17:38] pskosinski: has joined #ruby
[22:18:01] TinkerT: has joined #ruby
[22:18:15] weaksauce: has joined #ruby
[22:18:22] jrich523: yeah i had seen the dev dependencies.. but.. the only reason i was trying pry was to get better/clean inspect output.. so... i just sucked it up and read the horrible garbage it spewed out lol
[22:18:39] apeiros: though, since all that matters to a gem when publishing is the gemspec, it's fine to just put it into the gemfile.
[22:19:28] bauruine: has joined #ruby
[22:20:27] jrich523: ugh, im an idiot
[22:20:30] banisterfiend: has joined #ruby
[22:20:40] jrich523: it wasnt working because i had switched from strings to symbols for hash keys
[22:20:45] jrich523: so of course, ['site'] wont work
[22:27:30] fmcgeough: has joined #ruby
[22:27:52] kt: has joined #ruby
[22:31:10] EvilJStoker: has joined #ruby
[22:35:20] samort7: has joined #ruby
[22:40:03] pankaj: has joined #ruby
[22:41:13] pankaj: I am using linux and I have ruby and ruby docs installed on my system. But sometimes I have to find about the functionality about a function. How to find that using docs and docs?
[22:42:45] chouhoulis: has joined #ruby
[22:42:50] WAFFLEMAKER3000: has joined #ruby
[22:43:15] zenspider: pankaj: try `ri Array.join` in your terminal
[22:43:49] chouhoul_: has joined #ruby
[22:44:56] chouhoul_: has joined #ruby
[22:45:57] ramfjord: has joined #ruby
[22:46:06] chouhoul_: has joined #ruby
[22:47:00] chouhoulis: has joined #ruby
[22:47:03] shinnya: has joined #ruby
[22:48:11] chouhoul_: has joined #ruby
[22:49:16] chouhoul_: has joined #ruby
[22:50:23] chouhoul_: has joined #ruby
[22:51:24] chouhoul_: has joined #ruby
[22:51:49] ramfjord: has joined #ruby
[22:52:39] chouhoulis: has joined #ruby
[22:52:47] chris349: has joined #ruby
[22:53:05] chris349: I try to do a bundle install as non-root user, because when you run as root it gives you warning to NOT run as root
[22:53:41] chouhoul_: has joined #ruby
[22:53:42] orbyt_: has joined #ruby
[22:53:49] jrich523: but when you dont run as root it fails :)
[22:54:09] chris349: But then it pops up a prompt asking for the "password" (not clear which "password" is needed). I type my system user password, but then it says: Gem::FilePermissionError: You don't have write permissions for the /usr/local/rvm/gems/ruby-2.1.2/wrappers directory
[22:54:25] chris349: But if I use sudo I can use the command it gives to install that one particular gem
[22:54:37] chris349: But then bundle install gets stuck and I need to run a sudo command to manually install the next gem
[22:54:46] chouhoul_: has joined #ruby
[22:54:56] chris349: So how can I configure the bundle install sudo/password prompt to work correctly and install the gem, instead of failing
[22:55:21] darix: chris349: gem install --user-install maybe?
[22:55:27] darix: you dont need to install into the system path
[22:55:54] chouhoul_: has joined #ruby
[22:56:59] chouhoul_: has joined #ruby
[22:57:28] chris349: What is the difference between --user-install and --path vendor/bundle? Which is better?
[22:57:47] chris349: And if it warns to me run as root why does it fail as non-root? Shouldnt it just work?
[22:57:48] darix: chris349: for a rails app the 2nd is probably better
[22:58:07] chouhoulis: has joined #ruby
[22:59:07] chouhoul_: has joined #ruby
[23:00:19] chouhoul_: has joined #ruby
[23:01:19] chouhoul_: has joined #ruby
[23:02:25] chouhoul_: has joined #ruby
[23:03:35] chouhoulis: has joined #ruby
[23:04:41] chouhoul_: has joined #ruby
[23:05:43] chouhoul_: has joined #ruby
[23:06:51] chouhoul_: has joined #ruby
[23:07:53] chouhoul_: has joined #ruby
[23:07:57] ramfjord: has joined #ruby
[23:09:13] chouhoulis: has joined #ruby
[23:10:12] chouhoul_: has joined #ruby
[23:10:32] za1b1tsu: has joined #ruby
[23:11:15] chouhoul_: has joined #ruby
[23:12:24] chouhoul_: has joined #ruby
[23:13:26] chouhoul_: has joined #ruby
[23:13:53] ellcs: has joined #ruby
[23:14:32] chouhoulis: has joined #ruby
[23:14:46] jenrzzz: has joined #ruby
[23:15:41] chouhoul_: has joined #ruby
[23:16:45] chouhoul_: has joined #ruby
[23:17:43] RougeR: has joined #ruby
[23:17:43] RougeR: has joined #ruby
[23:17:53] chouhoul_: has joined #ruby
[23:18:57] chouhoul_: has joined #ruby
[23:19:59] chouhoulis: has joined #ruby
[23:20:10] cschneid: has joined #ruby
[23:21:11] chouhoul_: has joined #ruby
[23:22:10] chouhoul_: has joined #ruby
[23:23:21] chouhoul_: has joined #ruby
[23:24:25] chouchen_: has joined #ruby
[23:25:34] chouhoulis: has joined #ruby
[23:26:38] chouhoul_: has joined #ruby
[23:27:11] karapetyan: has joined #ruby
[23:27:45] chouhoul_: has joined #ruby
[23:28:45] chouhoul_: has joined #ruby
[23:29:56] chouhoul_: has joined #ruby
[23:31:00] chouhoulis: has joined #ruby
[23:31:05] bambanx: has joined #ruby
[23:31:27] tdy: has joined #ruby
[23:31:53] Kensei: has joined #ruby
[23:32:02] chouhoul_: has joined #ruby
[23:32:15] cthulchu: folks, I don't need to have classes. I can have a file that only has one line like rules = [{type:"dl",test:"signup",step:"success submission"}] and now when I require it, I have instant access to rules
[23:33:10] chouhoul_: has joined #ruby
[23:33:33] Kensei: the default regexp delimiter is '/', as in a lot of other languages. i.e., /foo/.class => Regexp. this can be overridden with %r (e.g., %r!foo!.class => Regexp)
[23:34:03] kt: has joined #ruby
[23:34:13] chouhoul_: has joined #ruby
[23:34:39] Kensei: but /foo/.to_s => '(?-mix:foo)'. is there any way to stringify /foo/ back to "/foo/" ?
[23:34:40] gigetoo: has joined #ruby
[23:35:14] havenwood: cthulchu: nope
[23:35:16] cthulchu: why do you tostring a regex?
[23:35:22] chouhoul_: has joined #ruby
[23:35:33] cthulchu: havenwood, why?
[23:36:02] Kensei: because i need to express it into workable JSON to be passed to mongo
[23:36:26] intheclouddan: has joined #ruby
[23:36:29] havenwood: cthulchu: the local variable wouldn't be available from the requiring binding
[23:36:30] chouhoulis: has joined #ruby
[23:36:35] havenwood: cthulchu: try it
[23:37:12] cthulchu: how do I make it accessible?
[23:37:21] cthulchu: how do I make it global, I guess
[23:37:24] Kensei: i need to turn {'expr' => /dev/} => '{"expr":/dev/}'
[23:37:37] cthulchu: cuz I don't care, I need a file with json to be imported
[23:37:39] chouhoul_: has joined #ruby
[23:37:51] cthulchu: I figured having a file with json in a variable will do the trick
[23:38:23] havenwood: Kensei: /foo/.source #=> "foo"
[23:38:35] chouhoul_: has joined #ruby
[23:39:17] havenwood: Kensei: Where's the input coming from? Is it trusted?
[23:39:27] Kensei: havenwood: that's not a regexp, it's a string. i need the / delimiters added.
[23:39:45] chouhoul_: has joined #ruby
[23:39:50] havenwood: Kensei: I just realized what you were wanting when you added the JSON example.
[23:39:56] havenwood: Kensei: Is it trusted input?
[23:40:13] havenwood: Kensei: require 'json/add/regexp'
[23:40:19] Kensei: it will be sanitised.
[23:40:45] havenwood: >> require 'json/add/regexp'; JSON.load({'expr' => /dev/}.to_json)
[23:40:46] ruby[bot]: havenwood: # => {"expr"=>/dev/} (https://eval.in/1020170)
[23:40:48] chouhoul_: has joined #ruby
[23:41:23] havenwood: Kensei: It's a little-known feature of JSON in Ruby, but it requires using JSON::load instead of ::parse.
[23:41:29] Kensei: but that's a hash, not JSON. the output needs to be {"expr":/dev/}
[23:41:56] chouhoulis: has joined #ruby
[23:42:16] havenwood: Kensei: What is it? Just a String format?
[23:42:23] Kensei: it's weird that // is the default make-an-re operator, but there's no way to get back to it.
[23:42:43] havenwood: >> {'expr' => /dev/}.inspect # Kensei
[23:42:44] ruby[bot]: havenwood: # => "{\"expr\"=>/dev/}" (https://eval.in/1020171)
[23:43:05] chouhoul_: has joined #ruby
[23:43:11] Kensei: still got '=>' not ':'
[23:43:47] havenwood: Kensei: that'd turn the String into a Symbol - I guess say more about what this is?
[23:44:11] Kensei: no, because it's ':' inside a string.
[23:44:12] chouhoul_: has joined #ruby
[23:44:52] Kensei: convert hash {'expr'=>/dev/} to string '{"expr":/dev/}'
[23:44:52] havenwood: >> {'expr' => /dev/}.inspect.gsub('=>', ':') # Kensei
[23:44:53] ruby[bot]: havenwood: # => "{\"expr\":/dev/}" (https://eval.in/1020172)
[23:45:07] havenwood: Kensei: Why?
[23:45:23] nicht: has joined #ruby
[23:45:25] havenwood: It's some kinda pseudo-JSON? Whatcha doing with it?
[23:45:28] chouhoul_: has joined #ruby
[23:46:24] chouhoul_: has joined #ruby
[23:46:29] droidburgundy: has joined #ruby
[23:46:32] Kensei: no, it's valid JSON. in jscript in the mongo shell, for example: db.coll.find({"expr":/dev/})
[23:46:35] havenwood: Kensei: It's near impossible to give you a proper solution with what you've specified. I mean the above matches your required output. Can all Hash rockets simply be turned into colons?
[23:47:22] chouhoulis: has joined #ruby
[23:47:53] Kensei: in ruby the selector is {'expr'=>/dev/}. i need to turn the ruby structure into something that can be used in jscript
[23:48:11] Kensei: >> {'expr'=>/dev/}.to_json
[23:48:12] ruby[bot]: Kensei: # => undefined method `to_json' for {"expr"=>/dev/}:Hash ...check link for more (https://eval.in/1020173)
[23:48:35] chouhoul_: has joined #ruby
[23:49:21] Kensei: (never used that before, followed your example)
[23:49:45] chouhoul_: has joined #ruby
[23:49:51] workmad3: has joined #ruby
[23:49:53] Kensei: so there's nothing in ruby that turns a Regexp instance back into something using the default delimiters.
[23:50:40] chouhoul_: has joined #ruby
[23:51:08] Kensei: thing is, the selector might be a deep structure, and i would rather not have to walk it to make the conversions.
[23:51:37] cthulchu: how do we require a json file and cast it into an object?
[23:51:46] chouhoul_: has joined #ruby
[23:52:12] havenwood: cthulchu: Read the file and JSON.parse it.
[23:52:18] havenwood: cthulchu: Read the JSON docs.
[23:52:31] cthulchu: just like in js
[23:52:41] cthulchu: can I require it instead?
[23:52:42] Kensei: okey, next question. is there a way to marshal a complete context such that it can be resumed after a Marshal.load ?
[23:52:49] cthulchu: I really don't like explicit FS
[23:52:52] havenwood: Kensei: You can create your own JSON serializer for Regexp, since Ruby supports that, but Regexp literals aren't valid JSON.
[23:52:53] chouhoulis: has joined #ruby
[23:53:07] Kensei: JSON.parse(File.read('foo.json'))
[23:53:19] cthulchu: can't be that easy
[23:53:24] cthulchu: is that path relative?
[23:53:27] Kensei: i do it all the time
[23:54:00] cthulchu: and does it have to be valid json?
[23:54:03] chouhoul_: has joined #ruby
[23:54:29] Kensei: cthulchu: well, you can wrap it in a rescue block..
[23:54:44] cthulchu: no need, but wow
[23:55:05] chouhoul_: has joined #ruby
[23:56:08] chouhoul_: has joined #ruby
[23:57:13] wontruefree: has joined #ruby
[23:57:21] chouhoul_: has joined #ruby
[23:58:22] chouhoulis: has joined #ruby
[23:59:32] chouhoul_: has joined #ruby
[23:59:37] Kensei: havenwood: so javascript considers {"expr":/dev/} valid, but it's not valid JSON?