#ruby - 12 May 2018
« Back 1 day Forward 1 day »
[02:13:48] garyserj: yes I understand programming languages, but ruby seems a bit different in the statement returning something
[02:14:37] garyserj: suppose I have a function r=def abc1; puts "gg"; end Then can I execute it through r?
[02:14:39] mozzarella: constructs that would be statements in other languages are expressions in ruby
[02:16:47] ruby[bot]: havenwood: # => private method `abc1' called for main:Object (NoMethodError) ...check link for more (https://eval.in/1003035)
[03:13:03] chris349: I have a rake task that runs fine from a crontab, but its getting to complex so I want to move it to a shell script. I copy all the env variables from my crontab, such as RAILS_ENV, but when I run the script it errors out because its not running in the right RAILS_ENV
[03:17:55] elomatreb: Are you absolutely sure you're setting the rails env correctly? (i.e. is it actually exported?)
[03:21:54] chris349: eldritch, I dont export it in the crontab. Whats the right way to export it in a shell script?
[04:14:42] elomatreb: chris349: Sorry, missed your reply. You need to either call it in the line where you invoke rails (RAILS_ENV=something rake sometask), or export the variable in general (export RAILS_ENV=something). Otherwise it's local to your shell script, and spawned child processes do not know about it
[06:07:54] Vashy: baweaver, if I refactor the code to no longer use the Ruby namespace, is it okay to keep the name of the project/gem as 'ruby-lspci' ?
[06:26:50] elomatreb: Vashy: The Rubygems guides recommend underscores for word separation: https://guides.rubygems.org/name-your-gem/
[07:55:45] Hanmac: in case of https://bugs.ruby-lang.org/issues/14249 is there someone else beside me that uses this? str[match_str]
[09:12:35] apeiros: hanmac: I'm aware this exists, but I've never used it and I don't remember seeing it in use. I think I'd use String#include? instead of String#[String] (at least I can't imagine a use case where it's not a test for inclusion)
[09:18:23] dminuoso: apeiros: A language shouldn't clean up its mess and toss out old and bad garbage?
[09:18:58] apeiros: dminuoso: it should. but I wouldn't call String#[String] a high priority target in that
[10:05:10] joro_: al2o3-cr, i am not familliar with ruby to be honnest, i just found this https://pastebin.com/FeqFS98r
[10:05:10] ruby[bot]: joro_: we in #ruby do not like pastebin.com, it loads slowly for most, has ads which are distracting and has terrible formatting. Please use https://gist.github.com
[10:12:16] al2o3-cr: joro_: that isn't even using the network_interface gem. that is loading yaml with returns a hash then accessing the key network_interface from the secrets hash.
[10:30:05] apeiros: or in plain ruby: File.read("/etc/resolv.conf").scan(/^nameserver (.*)/).map(&:first) # there may be nicer solutions than this
[10:35:36] apeiros: anyway, your subshell does not have more rights than the application running the subshell. so again: if your shellout works, this will work too
[10:38:09] joro_: it's not a big deal... i was just asking al2o3-cr about the useless cat... i am not familliar with ruby at all
[10:42:33] apeiros: I have to asks somebody to take a picture of me when I'm mad, I want to see that 😂
[10:47:57] al2o3-cr: joro_: require 'resolv'; Resolv::DNS::Config.new.lazy_initialize.nameserver_port # will get you an array of namerservers and ports
[10:58:52] al2o3-cr: joro_: you can read, you just can't write to resolv.conf without root priviledges
[11:28:48] Prutheus: Hello. I want to exit an if block before reaching end if an condition inside the if block matches.
[11:35:12] Prutheus: nah, i jsut wrap the code inside the if into a labmda block where i can use break inside
[11:36:29] apeiros: mid code break/returns are spaghetti code. you shouldn't do that. but it's of course your decision.
[11:39:33] apeiros: as said, google spaghetti code. in short: because it's convoluted and hard to read. which in turn makes it hard to maintain.
[14:55:45] apeiros: hanmac: sure. but when do you need that? you already have the needle. almost certainly in a variable even.
[14:57:50] apeiros: mostly because I know ~70%+ of ruby devs would have to consult docs to understand the first
[15:12:47] konsolebox: apeiros: you honestly find that clever and never wrote a code like that? because i find that very basic when it comes to scripting.
[15:32:37] konsolebox: al2o3-cr: both methods are ruby and are well-documented. one is just frowned upon by the "community" because of a collective philosophy or myth, or laziness to learn complete ruby programming knowledge. like a tribunal, they try to define how ruby should work.
[15:38:55] Omnilord: If the language provides a useful tool, and new developers don't know how to use it, then yes, they will have to reach for the docs. How else will they learn the language?
[15:41:20] konsolebox: al2o3-cr: i think i misread what you said. i thought you referred to ||= not being clever but ruby, hence i tried to explain that ||= is as documented as ||, in the sense that || can be used to define a fallback value..
[15:41:59] konsolebox: apeiros: yes obviously, but i compared not by how one is established or not, but the complexity on their mechanism.
[15:42:38] apeiros: code readability vs cleverness is not depending on the complexity of the involved mechanism.
[15:45:05] konsolebox: apeiros: well popularity is not the only factor in my opinion. it's also about the requirement for being a basic ruby programmer, and how easy it is to follow code. especially if they are just using basic syntax. it doesn't even involve multiple methods.
[15:47:57] apeiros: konsolebox: yes, I'd expect any halfway decent ruby programmer to be able to follow it. but code where I have to look up half of the methods in order to understand it is - even if I can perfectly follow it - not readable code.
[15:49:43] apeiros: that's also one reason while extracting into methods is a great pattern (and another where I don't know whether it's even got a name: assign to well named local variables). it gives information about intent. which means even if I don't know one or two methods, I can infer from context.
[15:50:26] havenwood: I'd not use String#[match_str] unless I meant to create a new substring object.