« Back to channel list

#ruby - 27 May 2019

« Back 1 day Forward 1 day »
[00:00:23] darix: has joined #ruby
[00:09:37] xlued: has joined #ruby
[00:11:22] skryking: has joined #ruby
[00:12:26] fphilipe_: has joined #ruby
[00:19:36] houhoulis: has joined #ruby
[00:28:46] phaul: has joined #ruby
[00:30:09] rubydoc: has joined #ruby
[00:54:04] esp32_prog: has joined #ruby
[00:55:16] bambanx: has joined #ruby
[01:01:37] orbyt_: has joined #ruby
[01:10:51] Fusl: has joined #ruby
[01:33:24] nowhereman: has joined #ruby
[02:23:10] tdy: has joined #ruby
[02:27:26] nfsnobody: has joined #ruby
[02:38:54] Ai9zO5AP: has joined #ruby
[02:41:41] Swyper: has joined #ruby
[02:42:19] esp32_prog: has joined #ruby
[02:43:24] fphilipe_: has joined #ruby
[02:48:04] octos: has joined #ruby
[03:03:44] nowhere_man: has joined #ruby
[03:09:47] braincrash: has joined #ruby
[03:25:29] staticx: has joined #ruby
[03:31:45] jenrzzz: has joined #ruby
[03:35:54] sagax: has joined #ruby
[04:08:04] Exuma: has joined #ruby
[04:30:37] esp32_prog: has joined #ruby
[04:33:08] fphilipe_: has joined #ruby
[04:34:18] xlued: has joined #ruby
[04:37:52] tdy: has joined #ruby
[04:38:49] mosh: has joined #ruby
[04:54:46] QCF: has joined #ruby
[05:16:25] conta: has joined #ruby
[05:18:06] laaron: has joined #ruby
[05:18:55] podlech: has joined #ruby
[05:19:21] dar123: has joined #ruby
[05:21:04] marmotini_: has joined #ruby
[05:30:11] _whitelogger: has joined #ruby
[05:31:30] dar123: hey guyz, i am creating a .conf file to template.erb. what is the best way to say if ENV exists then name=abc else name=default
[05:35:20] jenrzzz: has joined #ruby
[05:39:50] ur5us: has joined #ruby
[05:40:11] xco: has joined #ruby
[05:43:23] kyrylo: has joined #ruby
[05:43:52] stooj: has joined #ruby
[06:02:04] fphilipe_: has joined #ruby
[06:08:35] schne1der: has joined #ruby
[06:11:13] dtzuzu: has joined #ruby
[06:18:50] esp32_prog: has joined #ruby
[06:31:11] sauvin: has joined #ruby
[06:31:51] kapilp: has joined #ruby
[06:39:17] haxx0r: has joined #ruby
[06:40:16] marz_d`ghostman: has joined #ruby
[06:40:30] marz_d`ghostman: Using minitest, is there a method to run a code before all tests in a test class?
[06:42:02] aupadhye: has joined #ruby
[06:42:29] baweaver: https://twitter.com/keystonelemur/status/1132899310931066880
[06:42:35] baweaver: Here's a fun idea
[06:47:27] esrse: has joined #ruby
[06:49:23] lxsameer: has joined #ruby
[06:54:32] fphilipe_: has joined #ruby
[06:58:40] Cork: has joined #ruby
[07:04:13] skarlso: marz_d`ghostman hey, there is setup and teardown and before and after you can use. Are those what you are looking for?
[07:05:33] skarlso: https://apidock.com/ruby/MiniTest/Unit/TestCase/setup
[07:06:11] dionysus69: has joined #ruby
[07:07:51] TomyWork: has joined #ruby
[07:08:56] deepredsky: has joined #ruby
[07:10:13] nOwz: has joined #ruby
[07:12:36] schne1der: has joined #ruby
[07:14:14] Fusl: has joined #ruby
[07:22:20] fphilipe_: has joined #ruby
[07:23:12] jenrzzz: has joined #ruby
[07:28:50] ShalokShalom63: has joined #ruby
[07:37:30] ShalokShalom: has joined #ruby
[07:37:45] marz_d`ghostman: skarlso: I'm looking at something like the before(:all) of rpec. Those I think run before/after every test
[07:38:10] deepredsky: has joined #ruby
[07:38:22] skarlso: yeah, setup does run before all tests
[07:38:42] skarlso: oh hang on it's deprecated
[07:39:37] skarlso: https://github.com/seattlerb/minitest#unit-tests
[07:39:42] skarlso: it does seem to run before all tests
[07:41:48] marz_d`ghostman: skarlso: thanks, I'll look into it. As for the after(:all), I'm currently using Minitest.after_run { } :)
[07:42:57] tdy: has joined #ruby
[07:43:20] marz_d`ghostman: Ah, I need to run this with spec/describe
[07:43:20] esp32_prog: has joined #ruby
[07:55:49] shtirlic: has joined #ruby
[07:57:55] claudiuinberlin: has joined #ruby
[08:05:50] jenrzzz: has joined #ruby
[08:16:07] ur5us: has joined #ruby
[08:17:17] vondruch: has joined #ruby
[08:19:21] xuyuheng: has joined #ruby
[08:20:01] jenrzzz: has joined #ruby
[08:20:16] Fusl: has joined #ruby
[08:21:19] ellcs: has joined #ruby
[08:28:46] jenrzzz: has joined #ruby
[08:30:06] hightower2: has joined #ruby
[08:32:56] deepredsky: has joined #ruby
[08:35:08] conta: has joined #ruby
[08:35:19] jenrzzz: has joined #ruby
[08:38:33] Ai9zO5AP: has joined #ruby
[08:53:15] jenrzzz: has joined #ruby
[09:00:32] deepredsky: has joined #ruby
[09:02:09] conta: has joined #ruby
[09:36:37] DiscoM: has joined #ruby
[09:37:21] banisterfiend: has joined #ruby
[09:38:20] DiscoM: Someone is using this library ? https://github.com/aspettl/dns-zone i have some pb with the cname records, and my Ruby knowledge is to low to find the bug.
[09:45:02] Sylario: has joined #ruby
[09:55:46] Kestrel-029: has joined #ruby
[09:57:34] ljarvis1: has joined #ruby
[10:10:40] dtzuzu: has joined #ruby
[10:13:13] Swyper: has joined #ruby
[10:15:08] TomyWork: has joined #ruby
[10:17:02] Dbugger: has joined #ruby
[10:18:05] conta: has joined #ruby
[10:18:42] Dbugger: has joined #ruby
[10:21:58] TomyWork: has joined #ruby
[10:22:41] leitz: has joined #ruby
[10:22:49] ryouba: is there a way to make a regex gsub work like in https://regex101.com/r/Vaz661/2 (i.e. with global and multiline, named capture groups, substitution based on the group names)?
[10:23:18] deepredsky: has joined #ruby
[10:23:29] ryouba: (trying with `lines.gsub /.../m {|match| ...}` to no avail so far)
[10:26:35] ryouba: oh, even at https://rubular.com/r/WHXrCmrKPfQMAx it works just fine ... just in code i can't make it work ... it only keeps matching the occurances that have no newline in them
[10:28:06] ytti: personally i would go other way
[10:28:36] ytti: instead of doing complex regexp, i'd dos omething like this
[10:28:46] ytti: input.lines.each do |line|
[10:29:21] ytti: words = line.split
[10:29:41] ytti: next unless word[1][0..1] == '[['
[10:31:17] AJA4350: has joined #ruby
[10:31:18] ytti: usually if you need help with regexp, then regexp was not the right solution
[10:31:37] ryouba: ytti: seems like trying to deal with those entries that span 2 lines would be even more complex using that approach
[10:31:40] ytti: in terms of readability and maintainability
[10:32:13] ryouba: also that regex was really easy to come up with given the existence of pages like the two i linked ... so i wouldn't classify it as a "complex" one
[10:32:15] ytti: ryouba, sorry, i only saw first url, and it didn't have multilines
[10:32:31] ryouba: it's the exact same text
[10:32:32] ryouba: ACTION looks
[10:32:44] ytti: ryouba, aah just didn't scroll
[10:32:55] ytti: the view rendered in 'test string' box didn't contain multilines
[10:33:10] ryouba: yeah, it's only some of the lower entries
[10:33:28] ytti: i think multiple is possible with that loop still
[10:33:37] ytti: just push result to soem array, once result is complete
[10:33:46] ryouba: in general it seems like useful knowledge to me to know how Rubular deals with its user input
[10:38:27] ryouba: trying with your approach
[10:38:32] ryouba: this is becoming a complex algorithm
[10:45:31] TomyWork: has joined #ruby
[10:46:13] reber: has joined #ruby
[10:46:50] ytti: StringScanner may also be your friend
[10:47:41] jinie: has joined #ruby
[10:48:23] _axx: has joined #ruby
[10:48:58] dostoyevsky: has joined #ruby
[10:49:52] ua: has joined #ruby
[10:49:54] ryouba: ytti: it kind-of works now (https://gist.github.com/sixtyfive/e1f70533598daac01931e611790aaea7 ... except for some bug, that I'm hunting now). but it would definitely be much more elegant and easier to read if there was just a way to treat a string with newlines in it the same way that regex101.com and rubular.com do.
[10:54:09] jenrzzz: has joined #ruby
[10:58:05] fphilipe_: has joined #ruby
[11:03:00] ryouba: ytti: fixed all the bugs now (still https://gist.github.com/sixtyfive/e1f70533598daac01931e611790aaea7). it fulfills its purpose now, so thank you despite the differences in philosophy! :-)
[11:05:40] deepredsky: has joined #ruby
[11:06:14] ytti: ryouba, looks cleaner to me, but indeed, matter of opinion
[11:06:41] pwnd_nsfw`: has joined #ruby
[11:07:16] octos: has joined #ruby
[11:07:31] ytti: slightly related question, that pattern is something i also often do
[11:07:35] ytti: foo = []
[11:07:56] ytti: something.each { |x| foo << something(x) if sometimes }
[11:08:18] ytti: is there more idiomatic version? like maybe
[11:08:36] ytti: foo = something.map { |x| sometimes ? something(x) : nil }.compact
[11:08:58] ytti: or some other way to return different size enumerable
[11:09:40] phaul: something.select(&:sometimes)
[11:10:06] ytti: i thought select returns itself
[11:10:11] ytti: when true
[11:10:34] ytti: where as typically you want to mutate the return value
[11:10:55] ytti: so you'd rather foo = something,select(&:sometimes).map ...
[11:11:36] phaul: many ways to skin that cat :)
[11:12:11] ryouba: phaul: what about my original question ... how might rubular.com deal with its user input? i.e., a long, multiline string and a regex that (on regex101.com, i.e. in Perl lingo) would have "gm" as its options?
[11:15:44] phaul: I donno. I would have thought that rubular does what the ruby regex engine does. I don't know why you are seeing discrepancy
[11:19:20] UncleCid__: has joined #ruby
[11:23:33] deepredsky: has joined #ruby
[11:29:03] kyrylo: has joined #ruby
[11:41:12] jenrzzz: has joined #ruby
[11:46:52] Swyper: has joined #ruby
[12:03:31] ruby-lang461: has joined #ruby
[12:04:53] xuyuheng: has joined #ruby
[12:06:55] ryouba: phaul: i don't think there's a difference. i think i don't know how to use the ruby regex engine toward that end. my attempt was basically `str.gsub /regex/m, 'subst'` and my best guess as to why it didn't work is the lack of a 'g' option.
[12:11:22] vondruch_: has joined #ruby
[12:15:06] banisterfiend: has joined #ruby
[12:21:27] fphilipe_: has joined #ruby
[12:30:51] NL3limin4t0r: ryouba: Ruby regex have the Perl "m" option always enabled, in Ruby `^` and `$` alway match the start and end of an line. If you want to match the start and end of the entire string you'll have to use `\A` and `\z`. Ruby doesn't have the "g" option, depending on the usage it will automatically stop on the first match, or go through all matches.
[12:31:50] NL3limin4t0r: eg. text[regex] only matches ones, while text.scan(regex) matches all the posibilities.
[12:34:04] NL3limin4t0r: Ruby only supports the "m", "i" and "x" flags. From whom "i" and "x" are the same as in Perl while the "m" option in Ruby is equal to the "s" option in Perl.
[12:38:12] codefriar: has joined #ruby
[12:38:53] sagax: has joined #ruby
[12:40:45] Nicmavr: has joined #ruby
[12:59:12] salerace: has joined #ruby
[13:01:19] haxx0r: what's best way to work with a websocket api? i would think JavaScript can do it best?
[13:02:16] mnemon: haxx0r: plenty of implementations for common langs
[13:02:17] zodd: has joined #ruby
[13:02:24] mnemon: but depends what you're doing with it
[13:02:56] haxx0r: all the exchanges have websocket APIs
[13:03:00] haxx0r: so you get real time order book
[13:06:12] _whitelogger: has joined #ruby
[13:07:04] Talion: has joined #ruby
[13:09:48] deepredsky: has joined #ruby
[13:10:41] schne1der: has joined #ruby
[13:17:53] migalenkom: has joined #ruby
[13:22:24] dostoyevsky: has joined #ruby
[13:23:57] grilix: has joined #ruby
[13:29:44] haxx0r: i got it!
[13:36:00] doodleb46: has joined #ruby
[13:41:26] migalenkom: Hi there. I have a Texecom alarm connected to the serial port, and I am trying to read zones status page 2 of this manual.(https://drive.google.com/file/d/1Z3caY_y9wKAch7-tiZgAElWBY8uiZRxr/view?usp=sharing) I am getting some binary response but I cannot parse it correct. Could you please help me? Here is what I have already tried: https://dpaste.de/dhPD
[13:42:23] codefriar: has joined #ruby
[13:45:53] Azure|dc: has joined #ruby
[13:46:48] wildermind: has joined #ruby
[13:49:49] migalenkom_: has joined #ruby
[13:50:09] migalenkom_: has left #ruby: ()
[13:52:50] Inline: has joined #ruby
[13:55:45] Nicmavr: has joined #ruby
[14:00:00] doodleb4: has joined #ruby
[14:00:02] migalenkom_: has joined #ruby
[14:05:08] migalenkom__: has joined #ruby
[14:06:03] doodlebug: has joined #ruby
[14:06:41] jeremycw: has joined #ruby
[14:10:07] migalenkom_: has joined #ruby
[14:11:12] migalenkom_: has joined #ruby
[14:12:03] doodlebug: has joined #ruby
[14:16:53] cthulchu_: has joined #ruby
[14:24:21] spiette: has joined #ruby
[14:25:46] Kestrel-029: has joined #ruby
[14:27:37] migalenkom_1: has joined #ruby
[14:28:31] adam12: migalenkom_: If you want to get assistance for your issue, my suggestion is to digest it into a smaller, reproducable issue that shows what you're expecting and what you're getting instead. Not everyone will have knowledge of Texecom or serial ports, but might be able to assist you in decoding some binary if you show expected value. ie. foobar.unpack("*U") == "hello world" or something.
[14:28:57] deepredsky: has joined #ruby
[14:36:38] migalenkom_1: adam12: Could you please be so kind and open second page of the pdf https://drive.google.com/file/d/1Z3caY_y9wKAch7-tiZgAElWBY8uiZRxr/view?usp=sharing
[14:36:38] migalenkom_1: There described expected value and request example. There should be a number of each zone status from 0 to 7
[14:37:09] havenwood: migalenkom_: You need permission to view that doc.
[14:38:34] migalenkom_1: ah, i am sorry here is new link https://drive.google.com/file/d/1Z3caY_y9wKAch7-tiZgAElWBY8uiZRxr/view?usp=sharing
[14:38:36] deepredsky: has joined #ruby
[14:38:58] havenwood: migalenkom_1: 👍🏽
[14:42:31] ltem: has joined #ruby
[14:48:40] migalenkom_1: has joined #ruby
[14:49:14] laaron: has joined #ruby
[14:50:24] cthu|: has joined #ruby
[14:50:28] kapilp: has joined #ruby
[15:05:00] FastJack: has joined #ruby
[15:05:32] h3ll0w0rld: has joined #ruby
[15:11:32] adaedra: has joined #ruby
[15:13:59] havenwood: migalenkom_: when you write it just returns a single line with the read?
[15:16:02] Fusl: has joined #ruby
[15:18:15] Nicmavr: has joined #ruby
[15:18:29] ljarvis: has joined #ruby
[15:25:56] havenwood: migalenkom_: It looks like you're requesting a "read zone status" for zones 9-16, based on the docs. So you're expecting 16 bytes of data, followed by 0, 13, 10?
[15:26:31] havenwood: or the checksum, I guess, so 10, 13, 10?
[15:29:02] havenwood: migalenkom_: Did "Request Access with Control Panel" return "OK"?
[15:31:57] migalenkom_1: havenwood: yes, Request Access returned OK.
[15:32:26] havenwood: migalenkom_1: And it had the checksum and ended in 13, 10?
[15:33:41] havenwood: migalenkom_: It makes sense why 8 zones would give you back 16 bytes, but why no trailing C/SM, 0x0D, 0x0A?
[15:33:57] migalenkom_1: havenwood: the response on request access is OK\r\n without checksum
[15:36:58] migalenkom_1: havenwood: Maybe i sent request in some incorrect way.
[15:37:57] migalenkom_1: havenwood: But other requests that just returns OK or ERROR works
[15:38:56] weteamsteve: has joined #ruby
[15:39:32] deepredsky: has joined #ruby
[15:51:56] laaron: has joined #ruby
[15:52:42] migalenkom_1: here is e.g of other requests https://dpaste.de/WBwi
[15:55:32] tdy: has joined #ruby
[15:56:22] havenwood: migalenkom_1: What do you get if you query just zone 1?: "\\Z\x00\x01/"
[15:56:57] havenwood: "5C5A00012F"
[15:56:58] laaron: has joined #ruby
[15:59:39] graft: has joined #ruby
[15:59:39] graft: has joined #ruby
[16:01:59] conta1: has joined #ruby
[16:03:04] gix: has joined #ruby
[16:03:27] laaron: has joined #ruby
[16:08:31] ellcs: has joined #ruby
[16:09:25] havenwood: err, I think I read that wrong and that's ^ two zones. yeah, I think I made an off-by-one error >.> "number of zones from the start zone"
[16:09:26] havenwood: "5C5A00002F"
[16:09:53] havenwood: migalenkom_1: What's the value for a single zone? "\\Z\x00\x00/"
[16:10:07] m_antis: has joined #ruby
[16:10:57] migalenkom_1: havenwood: https://dpaste.de/Eava,
[16:11:49] havenwood: migalenkom_1: So it looks like it's returning [18, 8] for each zone ¯\_(ツ)_/¯
[16:12:40] havenwood: Which isn't what the spec says it'll return...
[16:13:02] migalenkom_1: "\\Z\x00\x00/" it returns a blank string
[16:15:25] havenwood: migalenkom_1: Looks like it should be something like "\x00\x00\r\n" or "ERROR\r\n"
[16:15:53] havenwood: migalenkom_1: Is there not a zone 1 or something?
[16:17:30] banisterfiend: has joined #ruby
[16:19:23] rippa: has joined #ruby
[16:21:54] migalenkom_1: havenwood: it should have: Number of wired zones (onboard) 4
[16:22:23] sameerynho: has joined #ruby
[16:22:24] migalenkom_1: Maximum number of wireless zones 64
[16:22:54] havenwood: migalenkom_1: Does the "Query Zone" command work?
[16:25:02] esp32_prog: has joined #ruby
[16:25:35] migalenkom_1: has joined #ruby
[16:25:42] migalenkom_1: havenwood: https://dpaste.de/TFxE
[16:25:51] Kestrel-029: has joined #ruby
[16:27:49] havenwood: migalenkom_1: So "Entry/Exit 1" and "Zone in Partition (area) 2"? Where are the "\r\n" on these?
[16:28:38] havenwood: migalenkom_1: And what the heck is [18, 8] supposed to mean?
[16:28:50] havenwood: "\\Z\x00\x01/" => [18, 8]
[16:30:38] havenwood: it's the bit they're looking at
[16:30:43] havenwood: i didn't read
[16:30:44] havenwood: ["00010010", "00001000"]
[16:33:24] havenwood: [{0=>"0", 1=>"0", 2=>"0", 3=>"1", 4=>"0", 5=>"0", 6=>"1", 7=>"0"},
[16:33:26] havenwood: {0=>"0", 1=>"0", 2=>"0", 3=>"0", 4=>"1", 5=>"0", 6=>"0", 7=>"0"}]
[16:33:58] codefriar: has joined #ruby
[16:34:10] havenwood: migalenkom_1: that's the [18, 8] you were getting back for each zone
[16:35:32] havenwood: I dunno why no \r\n
[16:36:28] banisterfiend: has joined #ruby
[16:40:24] al2o3-cr: havenwood: because in the Texecom class they've got device.readline.chomp
[16:40:34] havenwood: al2o3-cr: ah, i shoulda read the code
[16:40:39] havenwood: now it makes total sense
[16:40:41] havenwood: al2o3-cr: thanks!
[16:40:45] al2o3-cr: havenwood: np
[16:40:51] havenwood: migalenkom_1: so those are just the LBD and HBD, check the bits
[16:41:24] havenwood: migalenkom_1: al2o3-cr explained the no /r/n mystery - it's chomped in the code and I wasn't thinking about it being preprocessed before us seeing it
[16:45:05] havenwood: migalenkom_1: {"0:Healthy/1:Alarm"=>0, "0:Tamper/1:Shorted"=>1, "Fault Present"=>0, "Failed Test"=>0, "Alarmed"=>1, "Manual ypassed"=>0, "Auto Bypassed"=>0, "Always 0"=>0}
[16:45:32] codefriar: has joined #ruby
[16:47:19] deepreds1: has joined #ruby
[16:54:02] sagax: has joined #ruby
[16:54:27] sagax: has joined #ruby
[16:55:01] regedit: has joined #ruby
[16:55:56] iNs: has joined #ruby
[16:57:16] cthulchu_: has joined #ruby
[16:57:57] migalenkom_1: havenwood: thanks you so much, you made my day
[16:58:56] xagut: has joined #ruby
[17:01:00] migalenkom_1: al2o3-cr: thanks for explaining the no /r/n mystery
[17:01:44] al2o3-cr: migalenkom_1: np
[17:16:05] xagut: I'm toying with the ruby source. I added a `.second` method to Array. My change shows up in the the `miniruby` binary build but not the `ruby` binary (Even after a clean build).
[17:18:24] xagut: idk if anybody has any pointers on why that might be :-/
[17:19:06] comet23: has joined #ruby
[17:19:28] Tempesta: has joined #ruby
[17:19:35] comet23: i'm having trouble understanding what the value of power(base,exponent-1) is in the recursive call
[17:19:44] comet23: return base * power(base,exponent-1)
[17:20:53] cthu|: has joined #ruby
[17:21:24] graft: has joined #ruby
[17:21:25] graft: has joined #ruby
[17:23:25] cthu|: has joined #ruby
[17:25:55] mozzarella: comet23: 2^5 = 2 * 2^4
[17:27:12] rrichardsr3: has joined #ruby
[17:29:51] deepreds1: has joined #ruby
[17:29:52] phaul: comet23: http://www.pythontutor.com/visualize.html#code=def%20exp_2%28n%29%0A%20%20return%201%20if%20n.zero%3F%0A%20%202%20*%20exp_2%28n-1%29%0Aend%0A%0Aexp_2%285%29&cumulative=false&curInstr=25&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=ruby&rawInputLstJSON=%5B%5D&textReferences=false
[17:30:52] phaul: you can play with the forward / back buttons
[17:34:25] comet23: https://www.irccloud.com/pastebin/03Xcq2xT/power.rb
[17:34:26] ruby[bot]: comet23: we in #ruby do not like irccloud.com, it has no syntax highlighting, distracting formatting and loads slowly for most. Please use https://gist.github.com
[17:34:27] kyrylo: has joined #ruby
[17:35:40] comet23: the python tutor website is giving me errors
[17:35:45] esp32_prog: has joined #ruby
[17:37:36] phaul: you can go to http://www.pythontutor.com/visualize.html#mode=edit select Ruby as the language and paste your code in there
[17:38:06] comet23: https://www.irccloud.com/pastebin/bwMGufdj/
[17:38:06] ruby[bot]: comet23: as I told you already, please use https://gist.github.com
[17:39:17] phaul: ah, yours is infinite loop. you check base being zero not exponent
[17:39:20] comet23: you can't make anonymous gists anymore :*(
[17:39:30] comet23: oh thank you
[17:41:09] comet23: i still don't get it
[17:42:22] comet23: i don't get how the return value is doubling
[17:42:29] ShalokShalom: has joined #ruby
[17:43:31] phaul: each call was made from a call one step higher up which multiplies with 2 so it's multiplied after the return (not by that call but the call that called it
[17:44:46] phaul: it's hard to explain on irc. but when you return it's not doubled yet. It's going to be doubled in the caller
[17:44:53] comet23: i always thought my_function(n) evaluated to a single number
[17:45:09] comet23: do you have time? i'll send you money for explaining it
[17:45:31] phaul: I can try and might fail :)
[17:47:09] phaul: you do 5 calls all the way down to exp == 0 . f(f(f(f(f(0)))) at this point nothing is doubled and this is when the code in the innermost f hits the if condition
[17:47:56] phaul: it is returning 1, so now you have 4 f, with 1 bing inside the 4th. f(f(f(f(1))))
[17:48:55] phaul: the innermost is now in the base * f (... just finished with the evaluation of its f call, it was 1.
[17:49:16] phaul: so it itself returns 2 * 1. to the 3rd layer
[17:49:38] dar123: has joined #ruby
[17:50:49] phaul: the 3rd layer receives 2 from the 4th, whil it was doing base * f(.. so it itself returns 4 (2*2)
[17:50:55] phaul: end so on all the way up
[17:52:07] conta: has joined #ruby
[17:55:46] Nicmavr: has joined #ruby
[17:56:52] suukim: has joined #ruby
[17:59:55] phaul: yet another way of saying it is f(5) = f(2*f(4)) = f(2*f(2*f(3))) = f(2*f(2*f(2*f(2)))) = f(2*f(2*f(2*f(2*f(1))))) = f(2*f(2*f(2*f(2*f(2*f(0))))) = f(2*f(2*f(2*f(2*f(2*1))))) = f(2*f(2*f(2*f(2*2*1))))) = f(2*f(2*f(2*2*2*1))) = (2*f(2*2*2*2*1)) = (2*2*2*2*2*1)
[18:00:27] phaul: probably I messed up the number of parens here and there. but it shows what's happeneing
[18:02:17] phaul: ah I messed up the placement of fs on the way out. let me try with a smaller example:
[18:02:35] octos: has joined #ruby
[18:05:49] cd: has joined #ruby
[18:05:50] phaul: ah. it's much easier to explain this stuff on a whiteboard...
[18:06:42] phaul: comet23: did this help so far?
[18:09:36] dar123: has joined #ruby
[18:14:42] orbyt_: has joined #ruby
[18:18:57] hackeron: has joined #ruby
[18:24:32] NL3limin4t0r: comet23: It may become more clear when you rewrite the function as a while loop. https://gist.github.com/3limin4t0r/6a82e042fec1a0726ab1a2898f228c8a
[18:29:36] ravenousmoose: has joined #ruby
[18:31:54] NL3limin4t0r: Keep in mind that both variants drop into an endless loop if you provide a negative exponent.
[18:32:15] rubydoc: # => (1/16) (https://carc.in/#/r/6zqz)
[18:36:31] Frag: has joined #ruby
[18:37:59] altious: has joined #ruby
[18:45:27] gix: has joined #ruby
[18:46:26] laaron: has joined #ruby
[18:49:34] brool: has joined #ruby
[18:51:20] octos: has joined #ruby
[19:09:11] sagax: has joined #ruby
[19:11:30] octos: has joined #ruby
[19:12:15] ltem: has joined #ruby
[19:24:00] esp32_prog: has joined #ruby
[19:25:31] yasumi2136: has joined #ruby
[19:25:51] mjacob: has joined #ruby
[19:26:49] abaiste^: has joined #ruby
[19:27:24] gajus: has joined #ruby
[19:30:00] strmpnk: has joined #ruby
[19:31:46] mjacob: what's the most idiomatic way to have a sequence of statements and to use the result of the last statement in an expression?
[19:32:11] mjacob: i could have a 'if true' statement, but it's not very nice
[19:33:16] Nicmavr: has joined #ruby
[19:37:02] dar123: has joined #ruby
[19:40:31] chromis: has joined #ruby
[19:40:37] JJonah: has joined #ruby
[19:40:42] strmpnk: has joined #ruby
[19:41:30] raggi: has joined #ruby
[19:41:50] gajus: has joined #ruby
[19:42:14] ec: has joined #ruby
[19:42:35] fphilipe_: has joined #ruby
[19:43:17] manveru: has joined #ruby
[19:44:28] Lewix: has joined #ruby
[19:44:51] jhill: has joined #ruby
[19:45:02] englishm: has joined #ruby
[19:46:13] KevinSjoberg: has joined #ruby
[19:47:16] brool: has joined #ruby
[19:52:57] tdy: has joined #ruby
[19:54:53] jeremycw: just use a begin; end block
[19:55:21] jeremycw: a = begin; 'foo'; 'bar'; end
[19:55:40] esp32_prog: has joined #ruby
[19:57:57] hiroaki: has joined #ruby
[20:02:48] ravenousmoose: has joined #ruby
[20:10:46] Nicmavr: has joined #ruby
[20:20:06] orbyt_: has joined #ruby
[20:23:07] dar123: has joined #ruby
[20:31:32] octos: has joined #ruby
[20:36:46] houhoulis: has joined #ruby
[20:37:35] vondruch_: has joined #ruby
[20:40:52] Kestrel-029: has joined #ruby
[20:54:39] ur5us: has joined #ruby
[20:55:42] nowhere_man: has joined #ruby
[20:57:24] codefriar: has joined #ruby
[21:07:45] tdy: has joined #ruby
[21:11:26] hiroaki: has joined #ruby
[21:15:30] esp32_prog: has joined #ruby
[21:17:16] code_zombie: has joined #ruby
[21:24:07] Renich: has joined #ruby
[21:24:49] grilix: has joined #ruby
[21:26:23] staticx: has joined #ruby
[21:30:44] wildermind: has joined #ruby
[21:38:54] tdy: has joined #ruby
[22:23:39] baweaver: So I have a fun project: https://twitter.com/keystonelemur/status/1132899310931066880
[22:24:20] evdubs: has joined #ruby
[22:29:34] cthulchu_: has joined #ruby
[22:31:12] orbyt_: has joined #ruby
[22:32:32] hiroaki: has joined #ruby
[22:36:33] tsrt^: has joined #ruby
[22:39:14] FernandoB: has joined #ruby
[22:48:03] dar123: has joined #ruby
[22:58:38] Renich: has joined #ruby
[23:03:47] esp32_prog: has joined #ruby
[23:06:39] bambanx: has joined #ruby
[23:12:21] haxx0r: has joined #ruby
[23:15:22] hackeron: has joined #ruby
[23:19:05] dar123: has joined #ruby
[23:26:19] Azure: has joined #ruby
[23:30:53] Swyper: has joined #ruby
[23:32:40] haxx0r: XMR mooning, time to cashout boys!
[23:36:13] bsdbandit: has joined #ruby
[23:40:46] Nicmavr: has joined #ruby
[23:41:31] tdy: has joined #ruby
[23:51:21] dorian: has joined #ruby
[23:52:12] dorian: hey can somebody reset my brain here about calling a method with a predefined proc as if it was an inline block in the context of the caller?
[23:52:46] P0rkD_: has joined #ruby
[23:53:23] dorian: i have a bunch of dsl stuff i want to stick in a dispatch table
[23:54:25] dorian: essentially trying to metaprogram class Foo < Bar { dsl_here }
[23:55:18] mjacob: jerthank you, that does exactly what i need