DEV Community

Cover image for Why I love Ruby

Why I love Ruby

Vladislav Kopylov on March 04, 2024

I'm a back-end developer with over 8 years of coding experience. As a backend developer, I use lots of different languages to do my stuff, so I've ...
Collapse
 
dylannorthrup profile image
dylannorthrup

Thanks for the article! As a big Ruby fan I wholeheartedly agree with and endorse almost all of the statements in it! The one thing I'd take issue with is the implicit linking of Ruby with RoR.

The core of the Ruby ecosystem focuses on the single framework (RoR).

I've written (tens of?) thousands of lines of ruby code without most/all of it running either on back-end systems or manually by an engineer. Ruby was/is my replacement for the use cases I would have turned to Perl for: exploring a problem space[1] that doesn't require calling a bunch of external utilities[2] and which doesn't need to run across a wide variety of platforms[3].

It's good to hear the "Ruby != RoR" idea is popular in Japan. I just wish I had more command of Japanese so I could read understand the search results from ja.stackoverflow.com/

Thanks again for the article! Cheers


Footnotes
[1] So[4] many[5] reasons[6] for[8] this[9]
[2] Shell scripting (sh, bash, zsh depending on your tastes/environment) are much better for this pattern.
[3] Similar to perl back in the day, I don't want to have to install modules/gems on a multitude of systems to be able to run scripts. This is a config management headache I can generally sidestep using a compiled language like golang that encapsulates all of the dependencies during the compilation step.
[4] REPL via irb or the pry gem lets me explore "Why doesn't this work?" issues in their execution context and test out code solutions with a much tighter feedback loop.
[5] The object iterators (eg.foo.each do |f| ... end loops) make it quick and easy to apply a "here's how you do X to a thing of type Y" solution and apply it to a bunch of X. . . then, assuming you've avoided using variables from outside the loop, you can easily take the code inside the iterator block and move it to a method with almost no effort; and if you did use variables from outside the loop, it's only a small amount of effort.
[6] Monkey patching letting me augment existing types (including base types like Hash, Array, etc) with desired behavior[9] with much less effort than other languages (if it's possible at all).
[7] The gem ecosystem is as lively as the CPAN ecosystem was 20+ years ago, so normally someone else has already written a module for any integrations I need (with a special shout out to mysql2 which I've used for so many things over the years).
[8] Using rbenv to allow personal installation of gems makes it super easy to make use of third-party code when running from a workstation and testing things out. Automating rbenv installation (including gem installs) is not nearly as easy, but I tend to avoid ruby when it would involve running gem install or bundle install on more than a handful of hosts.
[9] Want to get a the union or intersection of two arrays a) without using set notation and b) while being able to use bang notation to apply the updates in a single statement?

class Array
  # Used for combining array elements
  #   combined_array = array1.union(array2)
  def union(new_a)
    dup.union!(new_a)
  end

  # Used for adding the contents of one array to another
  #   array1.union!(array2)
  def union!(new_a)
    self.replace(self | new_a)
  end

  # Used for finding common items between arrays
  #   common_items = array1.intersection(array2)
  def intersection(new_a)
    dup.intersection!(new_a)
  end

  # Used for adding the contents of one array to another
  #   array1.intersection!(array2)
  def intersection!(new_a)
    self.replace(self & new_a)
  end
end
Enter fullscreen mode Exit fullscreen mode
Collapse
 
kopylov_vlad profile image
Vladislav Kopylov

Thank you so much for your comment ♥️