#ruby - 05 September 2017
« Back 1 day Forward 1 day »
[00:54:26] DallasMikkjal: 6c 6f 6f 6b 69 6e 67 20 66 6f 72 20 69 6e 74 65 6c 6c 69 67 65 6e 74 20 6c 69 66 65 2c 20 70 6c 65 61 73 65 20 50 4d 20 6d 65
[01:08:36] TastyTrout: havenwood: he's spammed that in a few channels, then left right away. probably a bot.
[08:41:21] kapil___: I think its first check it its nil? or length = 0 if yes set "new card" else "params.i.name"
[08:47:14] elomatreb: kapil___: Be careful, it doesn't actually set anything unless there's something before or after that line you're not showing. This just returns values
[10:23:06] ccooke: dminuoso: But I use those all the... wait, you mean actual *class* variables, not *class instance* variables. Carry on celebrating ;-)
[11:09:02] f32: beginners question, but i am getting a undefined method `to_json' for NoMethod error using ruby at the command line (simple main.rb file) so... ruby main.rb
[11:11:34] f32: elomatreb: thanks, i just had found that, was in the last place i looked (the docs) :D
[11:12:20] elomatreb: Depending on how you installed Ruby you may have the docs installed locally for use with ri, which is pretty useful in cases like this one
[11:13:46] elomatreb: Well, now that I tried it it actually doesn't contain the one useful thing in this specific case, nvm
[11:42:14] ruby[bot]: dminuoso: # => no block given (LocalJumpError) ...check link for more (https://eval.in/855668)
[12:00:52] burgestrand: (The ampersand-proc style is not strictly necessary, I just got stuck doing it :d)
[12:04:18] burgestrand: It's a cheap way of guaranteeing that nested catches don't use the same label :p
[12:04:43] burgestrand: … does require you to pass the label down though, or pass down a `done` proc for each nesting
[12:05:27] TastyTrout: yeah. when i've seen try/catch used "done" would have to be passed through a huge callstack. but i can still see how it'd be useful
[12:08:52] TastyTrout: Burgestrand: could also be useful in cases like pry... eg there's: throw(:breakout), which makes ':breakout' reserved by Pry. so instead it could be, `throw pry.throwable` or sth.
[12:09:52] burgestrand: dminuoso I guess it makes sense, considering catch/throw can carry objects up the stack with it, why not carry an exception object :)
[12:10:02] ruby[bot]: dminuoso: I have disassembled your code, the result is at https://eval.in/855701
[14:39:29] ruby[bot]: -bbb canteen4!*@*$#ruby-fix-your-connection aduabu!*@*$#ruby-fix-your-connection *!*@c-24-6-102-219.hsd1.ca.comcast.net$#ruby-fix-your-connection
[15:32:28] havenwood: ErhardtMundt: Make sure to enable abort_on_exception or at least report_on_exception: Thread.abort_on_exception = true
[16:23:35] TastyTrout: code example would be best. you're talking words from your understanding, which may be wrong. so please share code for best results.
[16:40:23] j`ey: what am I doing wrong to get this to match the whole string? "1a1a1a1" =~ /((?:[0-9][a-f]))+/
[16:42:08] matthewd: j`ey: Your regex matches a sequence of one or more of (a number followed by a letter). Is that what you want?
[16:45:25] matthewd: If you want the whole match you can use $& (or #match etc), no need for a capture group
[17:10:39] guymanndude: hi folks, I'm wondering if there's an obvious way of solving my problem I haven't thought of: I want to populate a Ruby file with values from a YAML file
[17:11:07] guymanndude: I've loaded the YAML file, know how to access the keys I need...but how to interpolate that into the actual Ruby script?
[17:13:25] havenwood: guymanndude: What do you mean by "interpolate that into the actual Ruby script?" Do you want to iterate over every key/value or something else? Show us a gist of what you have so far?
[17:16:57] guymanndude: yup darix. I can change the state of the file by running it through Ruby, but am unsure as to how to "trigger" the interpolation/reading from the YAML file
[17:17:11] havenwood: guymanndude: Another way to get at those nested values is: file.dig 'key', 'value'
[17:19:19] havenwood: guymanndude: What's going on on line 6? What might `STUFF` be in your example?
[17:20:16] havenwood: guymanndude: Is `file["key"]["value"]` supposed to provide both key and value/
[17:21:47] havenwood: guymanndude: If `file["key"]["value"]` is already a Hash, see above ^. If it's something else, what is it?
[17:22:01] guymanndude: havenwood: so file["key"]["value"] is just giving the path to the exact value I want to interpolate there from the YAML file
[17:23:38] havenwood: guymanndude: As you have it, it's a syntax error. I'm curious what you mean the key to be?
[17:23:44] guymanndude: havenwood: it's an example key. in practice, it's our different environments in the YAML file (dev, test, qat, prod)
[17:24:58] guymanndude: you can ignore all that...here's a simpler example: https://paste.ee/p/fOG2h
[17:25:19] matthewd: Specific pair of .rb and .yml files, desired behaviour, and how the observed behaviour differs, please
[17:26:21] matthewd: It doesn't have to be your real code/data, but it does have to be something you've run locally to confirm it reproduces the situation you're in
[17:26:53] havenwood: guymanndude: In your example, you've assigned the constant `STUFF` to the `file["key"]["value"]` value. There's no apparent problem.
[17:27:04] guymanndude: matthewd: sure, here's a better link https://paste.ee/p/7uJ4T#U02tvHWFNvWkBU9rCRt1ArLBTLskW7Z6
[17:27:44] ccooke: dminuoso: it's a parser limitation. You can't pass a block with & because you've aready *ended* the parameter list
[17:28:01] guymanndude: havenwood: right, but I want the value from the YAML file to be interpolated into the ruby file
[17:29:46] guymanndude: right...but how do I get some_file.rb to go from the "templated" value to actually have the value from the YAML file interpolated?
[17:31:50] guymanndude: hmm, I've already written one that modifies YAML files like this...guess I have to have it handle Ruby files as well now
[17:31:54] havenwood: guymanndude: The Ruby script modifying itself is highly suspect. Can you tell us more about what you're doing?
[17:32:57] guymanndude: so I've already written a third script that goes out to the internet and populates a YAML file. Then I want to load data from that modified YAML file into another Ruby file
[17:33:45] havenwood: guymanndude: Why do you want Ruby to hardcode those values into its source code? What's the reason?
[17:34:24] havenwood: guymanndude: I mean why do you want to rewrite the Ruby file so the values are inline rather than simply deserializing them.
[17:34:25] guymanndude: it's to setup dev environments with credentials stored in a secure site online (think like lastpass/1password etc)
[17:35:06] matthewd: We understand why you need to load external data. We don't understand why you'd want to modify the actual script to do that.
[17:35:42] guymanndude: because for all intents and purposes the Ruby script is just more data/credentials
[17:37:06] guymanndude: how would you rewrite the file from the YAML file, essentially is what I'm asking
[17:37:59] matthewd: Ruby source is not, for any practical purposes: you're going to have to do bare string manipulation to shove the value into the right place
[17:41:50] guymanndude: just realized what I'm trying to do is self-modifying code and that this is a whole "Thing"
[17:42:11] guymanndude: ok, will continue my research there...apparently there's a thing called closures, sounds promising
[17:45:46] matthewd: You are / your boss is turning a very simple task into a very complicated one, for little to no obvious benefit. I'd be pushing back on the implementation detail, and just having ruby read the creds from the yaml file at runtime.
[18:56:16] TastyTrout: maybe you can use erb, to replace with the values in a `foo.rb.erb` file, then write the result as `foo.rb`, then run that.
[18:56:46] TastyTrout: i'm not sure why you'd want to make it more complicated but tbh using erb that way sounds interesting