Last active
December 14, 2015 12:38
-
-
Save dabit/5087199 to your computer and use it in GitHub Desktop.
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
def foo(options = {}) | |
[options[:bar], options[:baz]] | |
end | |
foo(bar: '12345', baz: 'abcdef') # => ["12345", "abcdefg"] | |
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
def foo(options = {}) | |
options = { bar: '12345', baz: 'abcdef' }.merge!(options) | |
[options[:bar], options[:baz]] | |
end | |
foo # => ["12345", "abcdefg"] | |
foo(bar: 'bar') # => ["bar", "abcdef"] | |
foo(bar: 'bar', baz: 'baz') # => ["bar", "baz"] |
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
def foo(bar: '12345', baz: 'abcdef') | |
[bar, baz] | |
end | |
foo # => ["12345", "abcdefg"] | |
foo(bar: 'bar') # => ["bar", "abcdef"] | |
foo(bar: 'bar', baz: 'baz') # => ["bar", "baz"] |
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
def foo(value, bar: '12345', baz: 'abcdef') | |
[value, bar, baz] | |
end | |
foo('VALUE') # => ["VALUE", "12345", "abcdefg"] | |
foo('VALUE', bar: 'bar') # => ["VALUE", "bar", "abcdef"] | |
foo('VALUE', bar: 'bar', baz: 'baz') # => ["VALUE", "bar", "baz"] |
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
allowed_methods = %i(get post put) | |
allowed_methods # => [:get, :post, :put] |
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
Car = Struct.new(:brand, :model, :color) | |
sporty = Car.new('Chevrolet', 'Corvette', 'Red') | |
sporty.to_h # => {:brand=>"Chevrolet", :model=>"Corvette", :color=>"Red"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment