Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Created June 1, 2015 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save KamilLelonek/238508fc474fa1a3b4ec to your computer and use it in GitHub Desktop.
Save KamilLelonek/238508fc474fa1a3b4ec to your computer and use it in GitHub Desktop.
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