Created
May 13, 2015 19:19
-
-
Save faoiseamh/08fab11a2dfb7ace4192 to your computer and use it in GitHub Desktop.
Ruby keyword arguments wtf
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
class Demo1 | |
def initialize a:, b: | |
@a = a | |
@b = b | |
puts "@a = #{@a.inspect} and @b = #{@b.inspect}" | |
end | |
end | |
Demo1.new a: 'one', b: 'two' | |
# ==> @a = nil and @b = "two" | |
class Demo2 | |
def initialize a:, b: | |
@wtf = 'asdfa' | |
@a = a | |
@b = b | |
puts "@a = #{@a.inspect} and @b = #{@b.inspect}" | |
end | |
end | |
Demo2.new a: 'one', b: 'two' | |
# ==> @a = "one" and @b = "two" | |
class Demo3 | |
def initialize a, b | |
@a = a | |
@b = b | |
puts "@a = #{@a.inspect} and @b = #{@b.inspect}" | |
end | |
end | |
Demo3.new 'one', 'two' | |
# ==> @a = "one" and @b = "two" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was an issue in Ruby 2.1.2