August 3, 2017 by Daniel P. Clark

Elixir Envy ᐅ Ruby

When a Rubyist learns about Elixir’s pipe operator and how it behaves similarly to Linux/Unix command line piping he, or she, very likely envies that feature and wishes to have it in Ruby.  How can I say that or how could I know that?  Well it’s a reasonable deduction when I see others, as well…

Continue Reading »

November 13, 2015 by Daniel P. Clark

Implement a Lazy Hash in Ruby

I use the term Lazy Hash in the same way you would call an Enumerator a lazy iterator.  That being; the values don’t get evaluated until they are needed.  In a Hash this is also utilizing memoization, where the value gets assigned the first time it’s used.  E.G. @variable ||= :value Let’s say you own…

Continue Reading »

March 3, 2015 by Daniel P. Clark

Ruby: The Case for Case

It’s nice to have case and when available in Ruby.  But I don’t see it used too often.  I myself don’t use it much because I’m more accustomed to just using if and else.  So let’s get into case switching. person = “employee” case person when “boss” puts “Yes sir!” when “employee” puts “Sure I’ll…

Continue Reading »

February 27, 2015 by Daniel P. Clark

Value Assignment and Deferment with Lambdas/Procs

When assigning a variable with a raw value the outcome is as you would expect. greeting = “hello” # => “hello” puts greeting # hello Now while learning about assigning methods to variables I used to wonder if I was assigning the result value from the method, or simply pointing to the method to be…

Continue Reading »

January 1, 2015 by Daniel P. Clark

When to use Ampersand and/or Colon with Proc, Map, and Inject

So with Ruby permitting Procs called on Objects I’ve found sometimes a Colon Method will work, and sometimes you need a Ampersand Colon Method.  For example, when I map &:upcase on a list of strings it works. [“a”,”b”,”c”].map(&:upcase) # = > [“A”, “B”, “C”] But if I try without the Ampersand I get: [“a”,”b”,”c”].map(:upcase) #…

Continue Reading »