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 »

May 13, 2017 by Daniel P. Clark

Don’t Use Objects as Hash Keys in Ruby*

Hashes have been optimized for symbols and strings in Ruby which technically are objects but this article is for revealing how much of a difference this makes when using other objects as hash keys.  There are some cases where this makes a big difference but many times you won’t notice much of a difference. I…

Continue Reading »

January 12, 2017 by Daniel P. Clark

Re: What is the splat operator doing here?

I’ve received an email from a fellow software developer inquiring about a bit of code where I use Ruby’s splat operator in two different ways.  In my Ruby gem cards_lib I wrote a “macro” to take a list of strings and generate card instances from them.  You don’t really hear of macros in the Ruby community…

Continue Reading »

April 21, 2016 by Daniel P. Clark

Use Ruby’s Refinements Anywhere With An Anonymous Class

For a long time I’ve been looking for a way to use Ruby’s refinements without building a class & method setup and then instantiating an instance of the class just to use it. And now I’ve finally found a solution. module Moo refine Fixnum do def to_s “moo” end end end # begin/end blocks allow…

Continue Reading »

March 7, 2016 by Daniel P. Clark

Make the Impossible Possible

[Don’t Listen to the Naysayers.] How many times have you heard that you can’t do this and you can’t do that and it’s never been done before? I love it when someone says that no one has ever done this before, because then when I do it that means that I’m the first one that has…

Continue Reading »

February 2, 2016 by Daniel P. Clark

Ruby: Bindings Across Inheritance

One thing you will find yourself needing to do is work across different scopes and in different ways.  I would like to show one way of modifying local variables by passing a Binding object. Let’s say you’re going to write encryption classes and you’ll have different ways of encrypting and decrypting.  For these you will have…

Continue Reading »

January 13, 2016 by Daniel P. Clark

101 Ruby Code Factoids

0) ‘methods’ method Since almost everything in Ruby is an Object you can type dot methods on it to see what methods are available. 4.methods – Object.methods # => [:-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :~, :&, :|, :^, :[], :<<, :>>, :to_f, :size, :bit_length, :zero?, :odd?, :even?,…

Continue Reading »

December 12, 2015 by Daniel P. Clark

Ruby: Arrays by Example

Arrays are Ruby’s most used collection type.  I will use very little description as I give examples for the many different ways to work with Arrays. Different ways to create an empty Array [] Array.new Array[] # same as :new Array(nil) # tries converting to an Array first and insures an Array result %w^^ #…

Continue Reading »

November 27, 2015 by Daniel P. Clark

Iterative Evaluation

In computer programming, an iterator is an object that enables a programmer to traverse a container, particularly lists. [1][2][3] -Wikipedia Gatcomb, Joshua. “Understanding and Using Iterators”. Perl.com. Archived fromthe original on 2005-06-16. Retrieved 2012-08-08. A user-defined iterator usually takes the form of a code reference that, when executed, calculates the next item in a list…

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 »

Page 1 of 5
1 2 3 5
1 2 3 5