#ruby - 07 May 2018
« Back 1 day Forward 1 day »
[07:20:37] bipul: Hi, I would like to know? How ruby gem is different from rvm(ruby version management) ?
[07:31:03] dminuoso: bipul: rvm is for switching entire ruby versions (say between 2.5.1, 2.4.4 and 2.3.7) while gem is for packaging ruby libraries and managing dependencies.
[07:31:39] dminuoso: bipul: If you don't have a good reason to use rvm I recommend to use chruby for version switching instead.
[07:39:17] dminuoso: bipul: `gem` is a library/format to bundle ruby programs/libraries. It also brings `gem` the executable that allows installing packages and their dependencies.
[07:40:45] bipul: okay, great. I wish i could find diagram to see how rubygem , bundle and rvm works together with each other.
[07:41:31] dminuoso: bipul: rvm/rbenv/chruby are only useful if you have some projects that need one Ruby version, while others need another.
[07:43:13] dminuoso: bipul: Okay so for more correctness: RubyGems is the name of the entire project. It consists of a format called `gem`, and brings a command line tool also called `gem`.
[10:55:29] shantanoo: hi, is there a way to find out whether the given string is ascii only or unicode?
[13:05:12] moeSizlak: if you have 2 versions of a gem installed, and 'require' the gem, which one will it use?
[13:11:40] dminuoso: moeSizlak: If you actually care, use #gem (e.g. gem "foo", "=1.2.3"; require 'foo')
[13:12:21] dminuoso: moeSizlak: I have never cared. If it matters to you, use bundler or pin like I asid.
[14:54:46] zxq2: if you're working with a library whose behavior wrt exceptions is poorly documented and may even change in the future, is it okay to catch all exceptions when calling a method, e.g.: recuse => e ...
[14:56:31] Cork: zxq2: i question if you should use a lib that doesn't have a stable structure for there exceptions...
[17:26:36] dminuoso: I regularly write Haskell code that generates Ruby code to do meta programming to generate bash scripts
[17:29:46] za1b1tsu: sorry for the mixed terminlogy, what I ment to say was shell scripts and I see a lot of people recommending python for shells scripts. And if I know ruby, was wondering if I could use it instead.
[17:30:00] konsolebox: za1b1tsu: a bash script is a shell script that works in bash. ruby runs ruby scripts. and a ruby script is not a shell script. learn basic meaning of terms. also, the command-line interface or the terminal is not "bash".
[17:32:37] za1b1tsu: konsolebox: so let me reprhase, use ruby for scripts to perform shell operations so I can automate different tasks in the shell
[17:35:46] konsolebox: za1b1tsu: if tasks are too complicated to be written with a bash/shell script, you can choose to write a ruby script. or if you're a purist you can just write a ruby script.
[17:38:32] za1b1tsu: konsolebox: I see, well python is mentioned a lot for writing these type of tasks and was curios if you guys still prefer to use ruby for this or use something else.
[17:43:35] konsolebox: za1b1tsu: python is more popular that i can say. and ruby in my opinion has steeper learning curve. python may also have better library support. but when it comes to ease of composing code in general, i'll always favor Ruby.
[17:59:02] gizmore: a customer once got hacked by DRI and Fairlight.. they made a beautiful index.php intro for they
[18:56:22] z64: heya dminuoso. if i've been following right, you've been getting into haskell yeah? would you have any sage words for a rubyists approach to haskell? i understand its best to take a blank canvas to it, i'm just struggling to find it as engaging to dive into as ruby was.
[19:04:52] tycoon177: does anyone here know of an alternative gem to rubyzip? we've been running into the same issue outlined here https://github.com/rubyzip/rubyzip/issues/249. Basically, *sometimes* the zip files generated by rubyzip can't be opened by the default archive utility on osx. I checked and all of the file names are unique. That was mentioned as a possible cause on that issue thread
[19:08:55] tycoon177: gizmore: i might look into doing that. Thanks! I was just wanting to make sure that I wasn't just missing another gem. I tried searching but didn't find anything
[19:09:46] gizmore: tycoon177: yeah... never had problems zipping with ruby.... doubt there is more than 1 zip lib
[19:28:42] z64: dminuoso: i've been picking it up/down for maybe a year. its been a bucket list thing for longer. i've always been more of a static typing / compiled lang guy, so haskells world of purity / type safety is super intriguing
[19:31:26] z64: i feel like what i need is like to take a class or something. i always wind up with way too many questions when i dive in than would be reasonable to dump onto someone for free.. lmao
[19:32:29] dminuoso: z64: The #haskell channel here on freenode is incredibly active and helpful. They can also point you to a lot of resources (from academic papers to books, or even some great free learning things)
[19:33:03] dminuoso: z64: But at the end you basically need to solve problems and write programs with it to get comfortable with it. Or perhaps Haskell just isn't your thing.
[19:33:52] z64: yeah i think thats the thing really. i need something practical to *do* with it beyond academic exercises, and its tough finding something when i could immediately do it in another lang i already know
[19:34:26] samosaphile: i don't understand this obsession with haskell/function programming at all. I can't think of anything built with haskell that I've ever used
[19:35:44] samosaphile: yet I've come across so many articles randomly searching for stuff about how to apply haskell/functional programming principles to x/y/z languages
[19:37:17] z64: dminuoso: compile time safety and strong typing is super valuable to me, in the kinds of bugs it eliminates from runtime entirely. and haskell seems to accomplish it in such a detailed, frighteningly interesting way lol.
[19:38:03] dminuoso: z64: Haskell goes way beyond "strong typing" in that you have an advanced type system in which can express so many things.
[19:44:43] dminuoso: z64: If you're solving problems in your comfort zone you will not expand knowledge.
[19:45:44] Eiam: as a ruby person who did that course, it was fun and #haskell was very helpful. I didn't have any issues
[19:47:05] dminuoso: z64: Learning requires accepting that it will take time, but it's an investment for the future. Me personally I just started solving typical day to day problems in Haskell.
[19:47:32] dminuoso: I've reached the point where the grand majority of "Hey I quickly need a program to do some data transformation" is just as quickly written in Haskell
[19:47:44] Eiam: z64: I did it to poke at Haskell and see what the fuss was about. I had fun, then I went back to mostly writing ruby but trying to be uhm, better about it?
[19:48:23] dminuoso: I think no matter whether you will stick to Haskell or not, it will make you a better programmer because it will teach you so many clean ways to think about problems and solve them.
[19:48:50] z64: dminuoso: yeah, i totally get that:) i tried cis194 a long time ago, i'll have to revisit it with gusto. and yeah, thats another reason why i was interested, from stories like those that i've heard ^^
[19:50:54] dminuoso: z64: The main thing to keep in mind is that a lot of the "traditional languages" are rather similar copies of another.
[19:51:19] dminuoso: So switching from say Python to Ruby doesn't really change how you are thinking, because the languages are basically the same with just some visual changes here and oddities there.
[19:52:18] dminuoso: But when you then pick up say.. Lisp, Prolog, Haskell, Idris or SML - you will notice that your "pattern recipes" stop working because you're toying around with different concepts
[19:52:51] dminuoso: Which is why these languages may seem so difficult to pick up compared to other languages, because they actually _are_ different.
[20:10:19] ruby[bot]: dminuoso: # => undefined method `last' for "_id_bar_id":String (NoMethodError) ...check link for more (https://eval.in/1000648)
[20:13:10] dminuoso: konsolebox: You allowed him to do what he has been doing for a year now. Drop into the channel and ask the most basic questions in hopes of people telling him how its done.
[20:20:00] konsolebox: kapil___: you already have the regex. you just need to apply regex comparison to the string.
[21:03:33] ruby[bot]: +bb hph^!*@*$#ruby-fix-your-connection *!*@ip72-195-187-57.mc.at.cox.net$#ruby-fix-your-connection
[21:27:49] garyserj: Why is it that when I do myFile=File.open("blah.txt","rb"); myFile.gets It interprets the new line. The myFile.gets shows the first line. Whereas isn't "rb" meant to be read-only, and binary. And wouldn't binary mean don't interpret new line? http://ruby-doc.org/core-2.5.0/IO.html#method-c-new "binary file mode Suppresses EOL <-> CRLF conversion on Windows"
[21:31:51] garyserj: Eiam: extension is irrelevant. and if a file is plain text it's still possible to read it as one reads a binary file
[21:32:52] Eiam: i could easily see a bug report that says "check magic header before opening files and ignore if the type doesn't match" or something
[21:32:57] garyserj: jordanm: so on unix it leaves \n as \n and in windows it converts \r\n to \n. ?
[21:33:43] jordanm: it does some kind of conversion on windows if you don't use it, but I am not sure exactly what
[21:35:08] jordanm: using "b" on windows should cause it to match the behavior of other operating systems (with or without "b")
[21:36:27] garyserj: it looks like 'b' on windows (and presumably unix), does nothing. But the default is in windows when ruby reads a file it converts \r\n to \n
[21:37:41] garyserj: if I wanted to treat new lines not as new lines but just as characters I suppose I could use .read instead of .open
[21:49:39] eam: jordanm: garyserj: that is not true - text/binary influences the character encoding of strings read from a file
[21:50:34] eam: this can be enormously important -- I once had a (unix) ruby script which went from hours of runtime to seconds after changing to binary
[22:49:12] garyserj: eam: do you have any practical example that shows that 'b' interprets the encoding differently?
[22:56:14] garyserj: I've noticed that "rb" can show an encoding of ASCII-8BIT and "r" can show it as CP850 but I don't see a difference.. and CP850 is a subset of ASCII-8BIT. Also one can specify an encoding e.g. myFile=File.open("blah.a","r:ASCII-8BIT") or myFile=File.open("blah.a","r:CP850") or myFile=File.open("blah.a","rb:ASCII-8BIT") or myFile=File.open("blah.a","rb:CP850") so when it even reports the same
[22:56:14] garyserj: encoding as specified then one can be even more sure that the 'b' or lack thereof is not influencing the encoding.
[22:59:19] lupine: http://ruby-doc.org/core-2.5.0/IO.html#method-c-new clearly documents the differences
[22:59:31] lupine: > Suppresses EOL <-> CRLF conversion on Windows. And sets external encoding to ASCII-8BIT unless explicitly specified.
[23:07:30] eam: garyserj: the difference is that a string will have indices access of O(n) instead of O(1) if the string uses a variable width encoding like UTF-8
[23:10:29] eam: with a fixed character size and O(1) indexing, the above will complete almost instantly
[23:10:47] eam: but if you do this when the string has a variable width encoding it will take a reeeeallly long time
[23:13:50] eam: worse, depending on the encoding, you may find yourself addressing the incorrect data because ruby strings have character semantics rather than byte semantics