« Back to channel list

#ruby - 13 August 2019

« Back 1 day Forward 1 day »
[00:10:35] skryking: has joined #ruby
[00:14:56] ramfjord: has joined #ruby
[00:19:56] tdy: has joined #ruby
[00:24:08] millerti: has joined #ruby
[00:25:41] duderonomy: has joined #ruby
[00:38:57] Nicmavr: has joined #ruby
[00:41:18] elphe: has joined #ruby
[00:52:27] Tempesta: has joined #ruby
[01:06:00] dviola: has joined #ruby
[01:18:19] AJA4351: has joined #ruby
[01:20:42] Swyper: has joined #ruby
[01:20:52] tdy: has joined #ruby
[01:22:18] code_zombie: has joined #ruby
[01:32:47] paraxial28: has joined #ruby
[02:02:31] bruce_lee: has joined #ruby
[02:05:07] henninb: has joined #ruby
[02:07:47] Technodrome: has joined #ruby
[02:34:59] Fusl: has joined #ruby
[02:49:54] kyrylo: has joined #ruby
[02:49:54] elphe: has joined #ruby
[02:52:50] kyrylo: has joined #ruby
[02:54:07] cd: has joined #ruby
[02:58:58] jenrzzz: has joined #ruby
[03:20:46] tsujp: has joined #ruby
[03:22:49] Swyper: has joined #ruby
[03:30:50] ramfjord: has joined #ruby
[03:36:26] kyrylo: has joined #ruby
[03:43:24] bitwinery: has joined #ruby
[03:44:49] tsujp: has joined #ruby
[03:53:31] kyrylo: has joined #ruby
[03:58:22] kyrylo: has joined #ruby
[04:21:24] jenrzzz: has joined #ruby
[04:26:16] za1b1tsu: has joined #ruby
[04:27:31] bitwinery: has joined #ruby
[04:34:34] Azure: has joined #ruby
[04:39:53] kyrylo: has joined #ruby
[04:53:43] ur5us: has joined #ruby
[05:00:49] lalitmee: has joined #ruby
[05:03:33] glosoli: has joined #ruby
[05:15:55] daniel: has joined #ruby
[05:20:32] Flyingdog: has joined #ruby
[05:24:02] kyrylo: has joined #ruby
[05:28:33] reber: has joined #ruby
[05:30:58] ramfjord: has joined #ruby
[05:31:09] kyrylo: has joined #ruby
[05:32:15] kyrylo_: has joined #ruby
[05:39:02] dionysus69: has joined #ruby
[05:51:11] _whitelogger: has joined #ruby
[05:57:10] _whitelogger: has joined #ruby
[06:06:03] moei: has joined #ruby
[06:12:16] duderonomy: has joined #ruby
[06:15:12] rheddry: has joined #ruby
[06:15:16] sauvin: has joined #ruby
[06:17:46] ellcs1: has joined #ruby
[06:26:50] aupadhye: has joined #ruby
[06:33:18] duderonomy: has joined #ruby
[06:41:35] lxsameer: has joined #ruby
[06:42:05] corellian: has joined #ruby
[06:47:38] kyrylo: has joined #ruby
[06:50:08] levifig: has joined #ruby
[06:51:33] elphe: has joined #ruby
[06:52:28] TomyWork: has joined #ruby
[06:54:15] ur5us: has joined #ruby
[06:59:51] suukim: has joined #ruby
[07:06:05] GodFather: has joined #ruby
[07:06:06] GodFather_: has joined #ruby
[07:23:25] fphilipe_: has joined #ruby
[07:31:18] ramfjord: has joined #ruby
[07:45:14] deepredsky: has joined #ruby
[07:57:07] jenrzzz: has joined #ruby
[07:57:53] baojg: has joined #ruby
[07:59:18] baojg: Hi, bug_db[project_name][ticket_id] = {title => title, 'due date' => t, note => description}, I wannt use 'due data' name as hash key, but it have blank char, is it correct to use here?
[07:59:37] baojg: due date as key name.
[08:00:13] lalitmee: has joined #ruby
[08:00:52] deepredsky: has joined #ruby
[08:02:09] vondruch: has joined #ruby
[08:05:50] queip: has joined #ruby
[08:07:17] duderonomy: has joined #ruby
[08:09:48] duderonomy: has joined #ruby
[08:12:09] phaul: baojg: what do you mean by key name? I think there is a misunderstanding in this here. Do you mean if it could be converted to a symbol? The answer is yes. it can be.
[08:12:23] phaul: &>> :'due date'
[08:12:28] rubydoc: # => :"due date" (https://carc.in/#/r/7e3l)
[08:13:18] muhaha: anyone knows omniauth ?
[08:16:29] jefffrails35: has joined #ruby
[08:17:36] phaul: &>> {'due date': 123} # the rocket syntax reveals that it's just a symbol as a key. the postfix : is just a shorthand for symbol keys..
[08:17:39] rubydoc: # => {:"due date"=>123} (https://carc.in/#/r/7e3m)
[08:23:31] ur5us: has joined #ruby
[08:25:08] ur5us: has joined #ruby
[08:43:32] TomyWork: has joined #ruby
[08:47:25] pascal: has joined #ruby
[09:02:15] kyrylo: has joined #ruby
[09:07:55] drnerdius: has joined #ruby
[09:12:51] nowhere_man: has joined #ruby
[09:13:58] yxhuvud: has joined #ruby
[09:20:27] tuor: has joined #ruby
[09:20:38] jefffrails35: has joined #ruby
[09:23:40] kyrylo: has joined #ruby
[09:31:25] skarlso: has joined #ruby
[09:41:39] tuor: I just build a (little) gem. I can use it. I have a script as example usage in my projects bin folder. Does this example script get into the gem or only my code in lib? If I give my built gem (.gem) to someone can he use my example usage script? If yes, how?
[09:47:56] ur5us: has joined #ruby
[09:50:13] drnerdius: has joined #ruby
[09:54:36] kyrylo: has joined #ruby
[09:54:39] ytti: Tuor, maybe do something like this gem.files = %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
[09:54:52] ytti: Tuor, gem.executables %w[bin1 bin2 bin3]
[10:20:29] tuor: Ah nice is working. Thx.
[10:23:13] jenrzzz: has joined #ruby
[10:25:45] drnerdius: has joined #ruby
[10:37:28] jenrzzz: has joined #ruby
[10:44:14] jenrzzz: has joined #ruby
[10:48:05] Bish: has joined #ruby
[10:48:12] Bish: how do i split an array to some condition?
[10:48:36] Bish: > "one\ntwo\ntree".lines.split(/^one/)
[10:51:14] Bish: surely could do that with inject
[10:51:26] Bish: but i wonder if there is a better way
[10:59:00] davor: has joined #ruby
[11:02:59] bmurt: has joined #ruby
[11:03:11] kyrylo: has joined #ruby
[11:07:15] kyrylo: has joined #ruby
[11:07:37] TomyWork: has joined #ruby
[11:15:54] ytti: Bish, it's not clear to me what you want to do
[11:16:02] Bish: basicially
[11:16:42] Bish: .each_with_object([[]]) { |acc,e| if condition then acc << []; acc << e }
[11:16:48] Bish: there must be a method like that
[11:17:46] Bish: .each_with_object([[]]) { |acc,e| if condition then acc << [] end; acc << e }
[11:18:24] ytti: perhaps give input and desired output
[11:18:29] tpanarch1st: has joined #ruby
[11:19:12] Nicmavr: has joined #ruby
[11:19:37] grilix: has joined #ruby
[11:19:55] ytti: perhaps Enumerable#partition but unsure
[11:20:01] ytti: would need to understand better what you need
[11:21:18] ytti: &>> (1..10).partition(&:odd?)
[11:21:20] rubydoc: # => [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]] (https://carc.in/#/r/7e4h)
[11:22:57] elphe: has joined #ruby
[11:29:14] jenrzzz: has joined #ruby
[11:37:56] baojg_: has joined #ruby
[11:38:14] jenrzzz: has joined #ruby
[11:39:05] AJA4350: has joined #ruby
[11:46:03] Swyper: has joined #ruby
[11:48:14] jenrzzz: has joined #ruby
[12:00:04] jenrzzz: has joined #ruby
[12:05:07] Bish: partition does only 2, but i want it like String#split
[12:14:02] jenrzzz: has joined #ruby
[12:16:32] phaul: &>> [1,2,3,1,2,2,2,1].slice_before(1).map {|a| a[1..]} # Bish
[12:16:34] rubydoc: # => [[2, 3], [2, 2, 2], []] (https://carc.in/#/r/7e52)
[12:17:10] phaul: although it break if it doesn't start with the delimiter item
[12:22:06] drnerdius: has joined #ruby
[12:23:42] yokel: has joined #ruby
[12:24:11] jenrzzz: has joined #ruby
[12:29:44] sagax: has joined #ruby
[12:36:29] Frobozz: has joined #ruby
[12:37:09] lucasb: has joined #ruby
[12:38:08] davorb: has joined #ruby
[12:49:35] quazimodo: has joined #ruby
[12:52:28] tsujp: has joined #ruby
[13:00:05] jenrzzz: has joined #ruby
[13:01:43] impermanence: has joined #ruby
[13:03:35] jbeaudoin_sher: has joined #ruby
[13:03:41] drnerdius: has joined #ruby
[13:16:14] bmurt: has joined #ruby
[13:22:12] involans: has joined #ruby
[13:27:27] brool: has joined #ruby
[13:30:57] EvilJStoker: has joined #ruby
[13:31:04] lupine: has joined #ruby
[13:31:32] krasnus: has joined #ruby
[13:33:39] sgen: has joined #ruby
[13:39:58] joast: has joined #ruby
[13:40:48] dionysus69: has joined #ruby
[13:43:56] alem0lars: has joined #ruby
[13:44:39] alem0lars: has joined #ruby
[13:46:37] grilix: has joined #ruby
[13:51:23] stryek: has joined #ruby
[13:57:32] involans: has joined #ruby
[13:59:25] rainmanj_: has joined #ruby
[14:00:58] jinie: has joined #ruby
[14:12:17] reber_: has joined #ruby
[14:26:11] vondruch: has joined #ruby
[14:33:02] havenwood: &>> [1,2,3,1,2,2,2,1].slice_after(1).to_a
[14:33:04] rubydoc: # => [[1], [2, 3, 1], [2, 2, 2, 1]] (https://carc.in/#/r/7e5r)
[14:35:53] baojg: has joined #ruby
[14:36:51] cthulchu: has joined #ruby
[14:37:11] dine: has joined #ruby
[14:46:29] vondruch: has joined #ruby
[14:51:32] vondruch: has joined #ruby
[14:56:50] aupadhye: has joined #ruby
[14:57:10] kyrylo: has joined #ruby
[14:59:39] kyrylo: has joined #ruby
[15:02:52] Darcy: has joined #ruby
[15:04:26] vdl: considering an array of strings ["foo", "bar", "baz"],how can I loop over all elements in the array? So that a variable equals "bar", then "baz", then "foo", ...
[15:05:28] also_uplime: &>> ["foo", "bar", "baz"].each {|val| p val}
[15:05:30] rubydoc: # => "foo" (https://carc.in/#/r/7e5x)
[15:06:13] vdl: not enough. If s="bar", next(s) must be "baz", then next(s) must be "foo", and so on.
[15:06:32] also_uplime: what are you trying to do? the array you showed isn't the same order you're requesting
[15:07:06] vdl: looping over an array of states name
[15:07:19] vdl: maybe with modulo and the index of a value?
[15:09:25] leftylink: is it not the case that you are rotating the array?
[15:10:24] vdl: What I want is a variable which iterates over "foo", "bar", "baz", "foo", "bar", "baz", "foo", "bar", and so on.
[15:10:38] leftylink: then you are asking for a cycle.
[15:11:02] leftylink: its name is #cycle
[15:13:15] dionysus70: has joined #ruby
[15:15:08] vdl: doesn't look like what I need
[15:15:18] englishm: has joined #ruby
[15:15:38] vdl: if you want, s++ must iterate over the array, that's all
[15:16:10] englishm: has joined #ruby
[15:16:16] Darcy: &>> ["foo", "bar", "baz"].cycle {|val| p val}
[15:16:33] rubydoc: # => "foo" (https://carc.in/#/r/7e5y)
[15:16:58] havenwood: &>> >> ["foo", "bar", "baz"].cycle.size
[15:16:59] rubydoc: stderr: -e:2: syntax error, unexpected >> (https://carc.in/#/r/7e5z)
[15:17:04] havenwood: &>> ["foo", "bar", "baz"].cycle.size
[15:17:05] rubydoc: # => Infinity (https://carc.in/#/r/7e60)
[15:18:05] vdl: nah, ["foo", "bar", "baz"].cycle {|val| p val} prints infinitely...
[15:18:25] leftylink: there you go then
[15:18:26] havenwood: vdl: How long do you want to print?
[15:18:27] leftylink: exactly what you wanted
[15:18:39] vdl: leftylink: no, told you.
[15:18:50] vdl: ok let me try to be clearer
[15:19:14] Frobozz_: has joined #ruby
[15:20:56] darkf: has joined #ruby
[15:24:54] chalkmonster: has joined #ruby
[15:26:50] cthu|: has joined #ruby
[15:29:25] LtHummus: has joined #ruby
[15:29:33] quazimodo: has joined #ruby
[15:29:49] vdl: Ruby being Ruby, I expect something smaller and less retard than my state_after method here: http://ix.io/1RwX
[15:30:08] morozovm: has joined #ruby
[15:30:15] jenrzzz: has joined #ruby
[15:37:42] kyrylo: has joined #ruby
[15:38:20] dviola: has joined #ruby
[15:41:23] Darcy: &>> ['foo', 'bar', 'baz'].rotate.cycle{|v| p v; sleep 1}
[15:41:29] rubydoc: # => "bar" (https://carc.in/#/r/7e65)
[15:42:09] elphe: has joined #ruby
[15:42:55] Darcy: actually your sample starts at 'baz', so...
[15:42:56] kyrylo: has joined #ruby
[15:43:03] Darcy: &>> ['foo', 'bar', 'baz'].rotate(2).cycle{|v| p v}
[15:43:14] rubydoc: # => "baz" (https://carc.in/#/r/7e69)
[15:48:13] jenrzzz: has joined #ruby
[15:48:21] Xiti: has joined #ruby
[15:52:09] vdl: I just need a method to iterate. I never said I wanted to print. #cycle is completely useless. What I need is exactly what is doing the state_after method. I just know that it can be written smarter. Forget about it guys...
[15:52:35] hutch: has joined #ruby
[15:52:57] also_uplime: you know that the printing isn't a part of the cycling right? thats just to show it cycling
[15:53:34] TomyWork: has joined #ruby
[15:54:20] Darcy: vdl: your code sample prints
[15:54:23] vdl: it cycles indefinitely, I don't want that. Just look at what state_after does. I don't know what else to tell you.
[15:54:28] havenwood: vdl: https://gist.github.com/havenwood/eb43888e72c192f733aa1f3e9b3eb4de
[15:54:36] vdl: darcy: forget about it ;-)
[15:55:15] Darcy: vdl: oh you want *only* what the state_after method does
[15:55:32] jenrzzz: has joined #ruby
[15:55:58] havenwood: &>> STATES = %w[foo bar baz].freeze; STATES.zip(STATES.rotate).to_h.freeze
[15:56:00] rubydoc: # => {"foo"=>"bar", "bar"=>"baz", "baz"=>"foo"} (https://carc.in/#/r/7e6t)
[15:56:09] lypsis: has joined #ruby
[15:56:28] vdl: darcy: that's what I asked for, yes. I even provide a (dirty) working example for you to understand. The loop/print was simply there to showcase how to use the method...
[15:56:52] canton7: vdl, your original question was "considering an array of strings ["foo", "bar", "baz"],how can I loop over all elements in the array? So that a variable equals "bar", then "baz", then "foo", ...". It sounds like that wasn't actually your question -- in that case, it's worth being clear that your original question is incorrect, otherwise people will
[15:56:52] canton7: still answer based in part on your original question
[15:58:27] kyrylo: has joined #ruby
[15:58:41] Darcy: vdl: def state_after(current_state); STATES[(STATES.find_index(current_state)+1) % STATES.size]; end
[16:00:37] lord4163: has joined #ruby
[16:00:38] canton7: ACTION likes havenwood's solution
[16:00:44] vdl: darcy: #find_index != #index ?
[16:00:52] fphilipe_: has joined #ruby
[16:02:04] Darcy: vdl: they're aliases? dunno, found it by searching 'find index'
[16:05:27] jenrzzz: has joined #ruby
[16:05:49] Darcy: ACTION likes Havenwood's solution better as well... just creates a map, no searching needed
[16:08:51] _serenity: has joined #ruby
[16:11:09] jenrzzz: has joined #ruby
[16:15:37] kyrylo: has joined #ruby
[16:16:42] woo: has joined #ruby
[16:17:40] woo: anyone knows how to solve this error: http://dpaste.com/2B9F1RZ.txt
[16:19:00] istrasci: has joined #ruby
[16:19:39] vdl: havenwood: cannot this be chained?
[16:20:08] istrasci: How I list all class methods defined for a Class? I can get the instance methods with MyClass.instance_methods. But how do I get the class methods?
[16:22:03] Darcy: istrasci Class.methods(false)
[16:22:07] jenrzzz: has joined #ruby
[16:22:24] istrasci: darcy: Thank you
[16:23:13] kyrylo: has joined #ruby
[16:24:34] kyrylo: has joined #ruby
[16:24:47] al2o3-cr: has joined #ruby
[16:26:35] davor: has joined #ruby
[16:26:52] al2o3-cr: has joined #ruby
[16:27:32] AJA4351: has joined #ruby
[16:31:56] poontangmessiah: has joined #ruby
[16:32:09] jenrzzz: has joined #ruby
[16:35:49] awayfrommypc1056: has joined #ruby
[16:36:25] fphilipe_: has joined #ruby
[16:39:05] woo: has joined #ruby
[16:40:35] leftylink: ah, that's too bad. but it looks like the matter has been resolved
[16:40:40] LtHummus: has joined #ruby
[16:45:09] GodFather_: has joined #ruby
[16:45:11] GodFather: has joined #ruby
[16:48:33] duderonomy: has joined #ruby
[16:51:20] kyrylo: has joined #ruby
[16:56:22] Nowaker: has joined #ruby
[16:56:41] woo: had some network problems.
[16:56:56] tdy: has joined #ruby
[16:58:28] woo: the database I'm trying to connect is mariadb.
[16:58:51] woo: does the mysql gem works for it?
[17:06:21] balo: woo: https://github.com/brianmario/mysql2#compatibility
[17:06:27] balo: this is the mysql2 gem
[17:06:35] wildtrees: has joined #ruby
[17:06:54] jenrzzz: has joined #ruby
[17:10:58] alem0lars: has joined #ruby
[17:11:43] woo: balo: thank you.
[17:15:56] hutch: has joined #ruby
[17:18:54] glosoli: has joined #ruby
[17:22:32] sh7d: has joined #ruby
[17:23:12] bhaak: how does cycle not solve that problem?
[17:23:51] bhaak: &>> c=['foo', 'bar', 'baz'].cycle; puts c.next; puts c.next
[17:23:56] rubydoc: # => foo (https://carc.in/#/r/7e7r)
[17:24:30] havenwood: bhaak: The problem as stated was different than the desired method behavior. ¯\_(ツ)_/¯
[17:24:53] jenrzzz: has joined #ruby
[17:27:12] bhaak: havenwood: yeah, I got that but the dirty solution does exactly what cycle does as well.
[17:27:27] bhaak: well, not cycle in itself. the Enumerator returned from cycle
[17:29:05] havenwood: bhaak: I'm guessing the example was artificially zoomed in, and the real use case doesn't work with #cycle. It's really hard to say without knowing what the real problem was. It'd be waaay easier for us to suggest good solutions if we knew what the real goal was.
[17:29:42] havenwood: xy problem, etc
[17:30:09] havenwood: bhaak: I agree with you, as far as cycle is the best solution for the stated problem.
[17:30:36] havenwood: Better questions, better answers.
[17:30:48] bhaak: but it was claimed that the dirty code did all it should do.
[17:31:13] bhaak: but yeah, given the poor phrasing. who knows
[17:32:41] jakeb3: has left #ruby: ()
[17:38:33] howdoi: has joined #ruby
[17:40:14] codefriar: has joined #ruby
[17:51:33] davor: has joined #ruby
[17:52:59] code_zombie: has joined #ruby
[17:55:38] Frem: has joined #ruby
[17:59:49] ramfjord: has joined #ruby
[18:00:00] chalkmonster: has joined #ruby
[18:00:38] code_zombie: has joined #ruby
[18:01:29] jenrzzz: has joined #ruby
[18:06:30] jenrzzz: has joined #ruby
[18:13:19] jenrzzz: has joined #ruby
[18:14:54] drnerdius: has joined #ruby
[18:16:55] im_saeed: has joined #ruby
[18:19:42] elphe: has joined #ruby
[18:20:33] gix: has joined #ruby
[18:20:34] Darcy: has joined #ruby
[18:27:13] im_saeed: has joined #ruby
[18:27:34] im_saeed: has joined #ruby
[18:29:00] im_saeed: has joined #ruby
[18:31:34] englishm: has joined #ruby
[18:34:40] d`arcy: has joined #ruby
[18:41:42] _serenity: http://temp.sh/VyMGr/unknown.png
[18:43:38] chalkmonster: has joined #ruby
[18:44:31] havenwood: _serenity: What's the meaning of this!?
[18:44:57] _serenity: i just left the client open for a few hours and no one said anything just joins/leaves
[18:45:15] conta1: has joined #ruby
[18:45:18] havenwood: _serenity: Maybe hide joins and leaves?
[18:45:40] havenwood: _serenity: We're all just waiting for someone to have a Ruby question. Apparently the docs are too good. :P
[18:45:46] _serenity: my point was that there was nothing else
[18:45:56] havenwood: _serenity: Do you have a Ruby question?
[18:46:00] havenwood: Nobody seems to...
[18:46:59] _serenity: well as it happens i do, not that i joined with the intention of asking it but maybe you know the answer
[18:47:47] _serenity: how is that returning from a block is a valid operation
[18:48:26] _serenity: is it because blocks envoke methods so you return from that method?
[18:48:47] _serenity: if so what are the practical uses of that if any
[18:52:54] phaul: a return in a block feels quite natural to me especially that local variables ripple through block boundaries, so blocksare really not like anonymous functions
[18:53:59] _serenity: right but why is it possible to return from a block, what is actually going on?
[18:55:04] phaul: it's a closure passed as an argument, while the receiver is running the block of code it can set where the return should return as part of the environment
[18:56:23] phaul: I mean the caller can set whereb it should return along with the environment. sorry
[18:57:45] hiroaki: has joined #ruby
[18:57:47] _serenity: so it is a return from the envoked method? as in `10.times {|i| return}` would return from Integer#times
[18:58:36] phaul: no. think of it as just giving you a tool to define your own control structures. It returns from where it lexically appears
[18:58:57] phaul: controlstructures like if else, for while until...
[18:59:04] havenwood: _serenity: That would return from the enclosing method. Outside a method, it would be a LocalJumpError
[18:59:08] havenwood: &>> def foo; 10.times {|i| return i}; 42 end; foo
[18:59:08] rubydoc: stderr: /home/carcin/carcin/sandboxes/ruby/sandboxed_ruby2.6.0: error while loading shared libraries:... check link for more (https://carc.in/#/r/7e83)
[18:59:15] havenwood: &>> def foo; 10.times {|i| return i}; 42 end; foo
[18:59:18] rubydoc: stderr: /home/carcin/carcin/sandboxes/ruby/sandboxed_ruby2.6.0: error while loading shared libraries:... check link for more (https://carc.in/#/r/7e84)
[18:59:30] _serenity: notice how i didnt use a method
[18:59:38] havenwood: _serenity: LocalJumpError
[19:00:03] havenwood: _serenity: The locality of return does vary between procs, blocks and lambdas. Ruby doesn't violate Tennet's correspondence principle.
[19:00:14] havenwood: Anyways, meeting. ;P
[19:00:30] drnerdius: has joined #ruby
[19:00:40] leftylink: whhat is this correspondence principle
[19:00:42] _serenity: &>> 10.times {|i| return}
[19:00:42] rubydoc: stderr: /home/carcin/carcin/sandboxes/ruby/sandboxed_ruby2.6.0: error while loading shared libraries:... check link for more (https://carc.in/#/r/7e85)
[19:01:41] havenwood: #!> LocalJumpError: unexpected return # _serenity
[19:01:58] involans: has joined #ruby
[19:02:12] _serenity: ruby 2.6.3 runs that silently
[19:02:14] phaul: it seems that carc.in has been updated, and got broken. 24 version works
[19:02:17] _serenity: there is no error
[19:02:28] phaul: &24>> 1 + 1
[19:02:28] rubydoc: # => 2 (https://carc.in/#/r/7e89)
[19:02:51] _serenity: &24>> 10.times {|i| return}
[19:02:51] rubydoc: stderr: -e:2:in `block in <main>': unexpected return (LocalJumpError) (https://carc.in/#/r/7e8a)
[19:03:11] _serenity: &24>> puts `ruby -v`
[19:03:12] rubydoc: # => ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux] (https://carc.in/#/r/7e8b)
[19:03:35] _serenity: im running a different version
[19:03:52] _serenity: so what changed
[19:04:30] phaul: nothing. 2.6.3 also LocalJumpErrors the same way
[19:04:49] _serenity: no it does not
[19:04:54] phaul: except ofc if it appears inside a def
[19:05:14] _serenity: okay so it doesnt LocalJumpError, this is the code: `10.times {|i| return}`
[19:05:19] _serenity: so whats going on
[19:07:54] _serenity: found an answer http://ruby-for-beginners.rubymonstas.org/blocks/return_values.html
[19:08:47] _serenity: &24>> p [1, 2, 3, 4, 5].detect { |number| number.even? }
[19:08:48] rubydoc: # => 2 (https://carc.in/#/r/7e8d)
[19:09:10] phaul: and where does that have a return in a block?...
[19:09:41] _serenity: the {} encloses a block
[19:10:10] phaul: yeah, I thought the discussion was about "return" literaly appearing inside blocks
[19:10:24] _serenity: does it matter if you use the keyword or not?
[19:11:00] _serenity: only if you're not returning from the bottom of the block i would have thought
[19:11:34] phaul: &24>> p [1, 2, 3, 4, 5].detect { |number| return number.even? }
[19:11:35] rubydoc: stderr: -e:2:in `block in <main>': unexpected return (LocalJumpError) (https://carc.in/#/r/7e8e)
[19:12:08] phaul: it's useful to think of a block likea user defined flow control
[19:12:18] phaul: like while/until loop etc
[19:13:21] phaul: it's the same jump error as this one:
[19:13:31] phaul: &24>> return if true
[19:13:32] rubydoc: stderr: -e:3: void value expression (https://carc.in/#/r/7e8f)
[19:13:47] kyrylo: has joined #ruby
[19:14:02] phaul: almost.. :) , anyways. it was here on 2.6.3
[19:14:29] gb_away: has joined #ruby
[19:14:32] ixti: has joined #ruby
[19:14:39] phaul: or just simply:
[19:14:44] phaul: &24>> return
[19:14:45] rubydoc: stderr: -e:3: void value expression (https://carc.in/#/r/7e8g)
[19:14:52] _serenity: on 2.6.3 im getting no output when using `return` and 2 as output when not using `return`
[19:15:07] _serenity: with this: `p [1, 2, 3, 4, 5].detect {|number| number.even?}`
[19:16:09] _serenity: does the `return` cause it to exit prematurely
[19:16:58] kyrylo: has joined #ruby
[19:17:01] leftylink: `return` exits the lexically enclosing function. perhaps I don't know you are interested in something like
[19:17:04] leftylink: &24>> def f(a); a.map { |x| return :actually_the_whole_thing_is_invalid if x == 7; x * 10 } end; p [f([1, 2, 3]), f([1, 4, 7, 10])]
[19:17:05] rubydoc: # => [[10, 20, 30], :actually_the_whole_thing_is_invalid] (https://carc.in/#/r/7e8h)
[19:17:20] leftylink: maybe you just really don't like the number 7 for some reason
[19:18:56] _serenity: i see, but then what is the difference between explicitly using `return` and just supplying a return value at the end of the block? i always thought it was just sugar and the intepreter assumed a return
[19:19:02] phaul: oh I know why the weird void value errors from the bot... the bots addition of begin..end screws up things
[19:19:35] leftylink: well, the `x * 10` demonstrates what happens if you don't use the `return` keywordc, doens't it?
[19:19:43] leftylink: &24>> def f(a); a.map { |x| x * 10 } end; p [f([1, 2, 3]), f([1, 4, 7, 10])]
[19:19:44] rubydoc: # => [[10, 20, 30], [10, 40, 70, 100]] (https://carc.in/#/r/7e8i)
[19:20:01] leftylink: in that case, you do not prematurely exit from `f`
[19:20:12] leftylink: so that is very different
[19:20:23] _serenity: yeah i saw that but what is the difference
[19:20:41] _serenity: besides the inclusion of `return`
[19:20:58] leftylink: where did 10 and 40 go in theh first example?
[19:20:59] leftylink: where is 100?
[19:21:26] leftylink: why is the result a symbol instead of an array?
[19:22:03] _serenity: because you are returning from f()
[19:22:23] _serenity: but what about if it wasnt enclosed in a function
[19:23:55] phaul: then LocalJumpError. We are going around in circles ...
[19:24:25] kyrylo: has joined #ruby
[19:24:30] _serenity: when not using `return`
[19:25:52] _serenity: this `p [1, 2, 3, 4, 5].detect {|number| number.even?}` outputs 2
[19:26:07] _serenity: this `p [1, 2, 3, 4, 5].detect {|number| return number.even?}` has no output
[19:26:21] _serenity: from stdout or stderr
[19:27:26] phaul: the latter does print the exception here on 2.6.3 as it should.
[19:27:46] phaul: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
[19:28:13] phaul: repl is the stock irb
[19:29:34] _serenity: im using the interpreter natively and its not showing any exception
[19:30:37] phaul: yeah. try it in a repl
[19:30:55] phaul: or catch exceptions to see if there were any
[19:31:30] leftylink: note that if you do `return; puts :hello`, hello is not output. therefore, same with `p [1, 2, 3, 4, 5].detect {|number| return number.even?}` , you should not expect that anything was output.
[19:32:29] _serenity: but why does it raise an exception on older versions
[19:33:27] ixti: Hi, all! I've ran into a weird behavior of `Array#each`. Can't make a short snippet that reproduces it, but it happens regular in production for us.
[19:34:46] baweaver: ixti: Doesn't really give us much to go on
[19:35:00] desperek: has joined #ruby
[19:35:24] baweaver: The first step to debugging is reproduction
[19:35:39] ixti: Sorry I thought I'll be able to describe the problem in second message before getting the reply :D
[19:37:10] kyrylo: has joined #ruby
[19:38:07] jakeb2: has left #ruby: ()
[19:39:08] leftylink: it would be an exception in older versions because top-level return was not added until 2.4, right? https://bugs.ruby-lang.org/issues/4840
[19:39:08] _serenity: if its taking you that long to type then use https://pastebin.com/
[19:40:32] _serenity: thank you, leftylink that was the explanation i was lookingfor
[19:40:35] baweaver: dpaste.de is preferred, less ads and shenanigans
[19:41:22] kyrylo: has joined #ruby
[19:41:39] _serenity: didnt know about dpaste.de, nice
[19:43:04] kyrylo: has joined #ruby
[19:44:04] ixti: If would be able to reproduce the error - most likely I would not need a help. The problem that it happens in production and I can't nail down the root cause, so I feel like I'm missing something...
[19:44:07] ixti: https://gist.github.com/ixti/32c9fabe344de46c9986228aa18de253
[19:44:31] ixti: So, we use sidekiq, and the job looks like ^^^
[19:45:27] ixti: And sometimes, it fails with *undefined local variable or method \`step_options'*
[19:45:55] ixti: (i've updated gist just now - initial upload contained a typo)
[19:46:53] ixti: In other words, somehow, under some circumstances `step_options` becomes undefined within `STEPS.each { |step_options| ... }` loop
[19:47:14] kyrylo: has joined #ruby
[19:47:50] sameerynho: has joined #ruby
[19:47:50] ixti: For now we solved the problem by replacing `STEPS.each` with `STEPS.dup.each`.
[19:48:05] ixti: But I would like to know if that's known behavior
[19:49:20] jenrzzz: has joined #ruby
[19:58:38] codefriar: has joined #ruby
[19:58:47] kyrylo: has joined #ruby
[19:58:55] involans_: has joined #ruby
[20:01:09] Technodrome: has joined #ruby
[20:03:48] _serenity: has left #ruby: ("WeeChat 2.5")
[20:06:06] jenrzzz: has joined #ruby
[20:06:56] kyrylo: has joined #ruby
[20:18:40] troulouliou_div2: has joined #ruby
[20:27:03] grilix: has joined #ruby
[20:37:41] glosoli: what is the most typical data format ruby devs store configs that are prone to change over the time?
[20:43:35] SeepingN: has joined #ruby
[20:48:00] jenrzzz: has joined #ruby
[20:49:11] leftylink: interesting. I had thought that for `a.each { |x| ... }` that during the block `x` would surely be defined. I guess I will belearning something new today when thhe reason is figured out.
[20:49:33] cliluw: has joined #ruby
[20:50:06] queip: has joined #ruby
[20:51:10] AJA4350: has joined #ruby
[20:59:53] elphe: has joined #ruby
[21:03:23] ur5us: has joined #ruby
[21:23:10] queip: has joined #ruby
[21:26:01] ruby[bot]: -b *!*@90.207.25.70$#ruby-banned
[21:29:51] tdy: has joined #ruby
[21:37:48] jenrzzz: has joined #ruby
[21:42:47] regedit: has joined #ruby
[21:44:09] desperek: good evening
[21:44:18] regedit: how do i write a file contents as a string to database, and then later load this string back from database and use it as a file?
[21:44:54] regedit: this particular table/column in database is 'text' so i dunno about having a dedicated binary/blob column for this purpose...
[21:46:06] havenwood: regedit: What do you mean by "use it as a file?"
[21:46:33] regedit: havenwood: ideally i could IO open it etc. using it with libraries that expect to work on a file
[21:46:59] regedit: so like maybe i need to write the stuff to a TempFile or something
[21:47:08] cd: has joined #ruby
[21:47:41] regedit: i guess i'm more concerned about the first part: someone uploads a file, i have its UploadedFile TempFile with binary content, how do i save that content as string to database for later usage
[21:48:40] havenwood: regedit: What's the problem with saving it to the DB? What isn't working?
[21:48:58] desperek: you need a driver for your database and then insert the data with it
[21:49:10] desperek: or just use an array
[21:49:17] desperek: or maybe dont
[21:49:25] SuperLag: has joined #ruby
[21:50:33] regedit: ehm... i guess i havent tried 🤔 perhaps i was preemptively worried that if i do that it might explode on unexpected binary bytes when it expected sane string data... like maybe when it tries binding the data into the insert statement it would mess up or something... but maybe you're right i should TIAS first
[21:51:41] desperek: well, you can sanitize
[21:53:13] regedit: i could maybe just json encode or base64 encode the file contents, but i was wondering if there's some other known way how to safely save raw file binary as string to database
[21:53:55] regedit: either way imma first try the naive way and see if anything wrong happens
[21:54:09] regedit: desperek: what kind of sanitization?
[21:54:49] havenwood: regedit: The issue I've run into is needing to split files across rows. It works well.
[21:54:59] desperek: regedit, oh well i meant like remove all characters that are not in ascii or something
[21:55:07] desperek: but yeah, idk about saving blobs or binary data really
[21:55:49] regedit: havenwood: not sure i'll need that, in this case i THINK (hope...) the whole lot of binary content can fit in a single row text field
[21:55:53] havenwood: regedit: There are some caveats, so I'd reference a gem that does it.
[21:56:22] regedit: havenwood: sure what's the gem
[21:57:18] havenwood: regedit: I don't remember. I used a paperclip-like thing with Postgres.
[21:58:26] aphprentice__: has joined #ruby
[21:59:29] Nicmavr: has joined #ruby
[22:02:11] kaleido: has joined #ruby
[22:03:07] FastJack: has joined #ruby
[22:03:16] jenrzzz: has joined #ruby
[22:05:25] cthulchu: has joined #ruby
[22:09:42] kaleido: has joined #ruby
[22:16:58] jenrzzz: has joined #ruby
[22:18:02] havenwood: regedit: https://www.postgresql.org/docs/current/storage-toast.html
[22:19:02] regedit: 🤔 interesting
[22:23:11] AndreYuhai: has joined #ruby
[22:23:11] chalkmonster: has joined #ruby
[22:24:05] Leopere: has joined #ruby
[22:24:33] AndreYuhai: Hey there, I have a class and I am including a module to create database tables. But for example I will need more than 2 create table methods each of them creating a different table. How can I separate them using namespaces or modules? I got a bit confused.
[22:29:08] AndreYuhai: I mean how can I use my create_table method like ModuleName.create_table ? Because when I make it a class method then I can not use the instance variable from the class in which I am including the module.
[22:29:13] cthu|: has joined #ruby
[22:29:50] entel: has joined #ruby
[22:31:05] ur5us: has joined #ruby
[22:32:00] ruby[bot]: entel: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[22:34:09] phaul: entel: right now you can get a working in chat repl with &24>> prefix . I know...
[22:34:36] poontangmessiah: has joined #ruby
[22:38:01] regedit: havenwood: well here we have it: the specific error if i try saving file binary data to an ActiveRecord string field value: "incomplete multibyte character"
[22:39:14] woo: I'm having trouble loading a class. This is the code being used to lookup for ruby files: http://dpaste.com/2YFPJFX.txt
[22:40:33] woo: but this error pops up: http://dpaste.com/16YQ17B.txt
[22:41:05] woo: Base is the parent class of the one causing trouble.
[22:41:38] woo: but it has other children which operate normally through this same method.
[22:41:47] entel: &24>> 1+1
[22:41:47] rubydoc: # => 2 (https://carc.in/#/r/7e9t)
[22:41:52] entel: phaul: thanks
[22:42:13] gix-: has joined #ruby
[22:49:51] Swyper: has joined #ruby
[22:51:12] poontangmessiah_: has joined #ruby
[23:00:07] elphe: has joined #ruby
[23:00:20] Mark22k: has joined #ruby
[23:03:21] havenwood: regedit: Does the Postgres encoding match the file? Consider Base64ing before saving to DB.
[23:03:39] regedit: yep trying base64-ing now...
[23:04:05] havenwood: regedit: I wish I had a gem link, but I'm too busy to search for it. The one I used saved to PG across rows and worked well. I'm presuming it Base64ed. I vaguely recall that it did.
[23:07:44] bvdw: has joined #ruby
[23:11:33] gb_away: has joined #ruby
[23:12:05] Swyper: has joined #ruby
[23:13:00] troulouliou_div2: has joined #ruby
[23:13:11] Swyper: has joined #ruby
[23:17:32] bruce_lee: has joined #ruby
[23:17:32] bruce_lee: has joined #ruby
[23:24:10] AndroidKitKat: has left #ruby: ("WeeChat 2.5")
[23:38:33] Mark22k: has joined #ruby
[23:42:46] chalkmonster: has joined #ruby
[23:51:16] AndroidKitKat: has joined #ruby
[23:52:58] AndroidKitKat: has left #ruby: ()
[23:53:00] regedit: i see oh well
[23:53:14] regedit: thanks either way havenwood 👍
[23:55:01] RiPuk: has joined #ruby
[23:58:39] jenrzzz_: has joined #ruby
[23:59:28] tdy: has joined #ruby