Ruby Symbols:
# Symbols start with a colon
:action.class == Symbol
:action.to_s == "action"
:action == "action".to_sym
# There is only one instance of every symbol
:action.equal?(:action) # => true
'action'.equal?('action') # => false
# Symbols are typically used as keys in hashes
my_hash = {:controller => "home", :action => "index"}
:action.class == Symbol
:action.to_s == "action"
:action == "action".to_sym
# There is only one instance of every symbol
:action.equal?(:action) # => true
'action'.equal?('action') # => false
# Symbols are typically used as keys in hashes
my_hash = {:controller => "home", :action => "index"}
More about Methods:
- Arbitrary number of arguments: def my_methods(*args)
- Converting Array to arguments: my_method([a, b]*)
- Dynamic method invocation: object.send(:method_name)
- Duck typing: object.respond_to?(:method_name)
- If the last argument is a Hash, the braces can be omitted: link_to("Home", :controller => "home")
hope you learn today post.
Leave comment or share.
No comments:
Post a Comment