Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Monoids examples in Ruby
[1] (pry) main: 0> 1.class
=> Fixnum
[2] (pry) main: 0> 1.method(:+)
=> #<Method: Fixnum#+>
[3] (pry) main: 0> 1 + 0 == 0 + 1
=> true
[4] (pry) main: 0> 2.0.class
=> Float
[5] (pry) main: 0> 2.0.method(:*)
=> #<Method: Float#*>
[6] (pry) main: 0> 2.0 * 1 == 1 * 2.0
=> true
[7] (pry) main: 0> [].class
=> Array
[8] (pry) main: 0> [].method(:+)
=> #<Method: Array#+>
[9] (pry) main: 0> %i(a b) + [] == [] + %i(a b)
=> true
[10] (pry) main: 0> {}.class
=> Hash
[11] (pry) main: 0> {}.method(:merge)
=> #<Method: Hash#merge>
[12] (pry) main: 0> {}.merge(a: 1) == { a: 1 }.merge({})
=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment