-
-
Save guilleiguaran/c75b4c2052d2105b6d1832e8c7ebb62d to your computer and use it in GitHub Desktop.
Monoids examples in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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