mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-24 10:01:38 +00:00
Merge pull request #2834 from wwalker/master
[ruby/en_us] Ruby has "methods" not "functions"
This commit is contained in:
commit
3c28b2c360
@ -359,13 +359,13 @@ ensure
|
|||||||
puts 'This code always runs no matter what'
|
puts 'This code always runs no matter what'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Functions
|
# Methods
|
||||||
|
|
||||||
def double(x)
|
def double(x)
|
||||||
x * 2
|
x * 2
|
||||||
end
|
end
|
||||||
|
|
||||||
# Functions (and all blocks) implicitly return the value of the last statement
|
# Methods (and all blocks) implicitly return the value of the last statement
|
||||||
double(2) #=> 4
|
double(2) #=> 4
|
||||||
|
|
||||||
# Parentheses are optional where the result is unambiguous
|
# Parentheses are optional where the result is unambiguous
|
||||||
@ -399,7 +399,7 @@ surround { puts 'hello world' }
|
|||||||
# }
|
# }
|
||||||
|
|
||||||
|
|
||||||
# You can pass a block to a function
|
# You can pass a block to a method
|
||||||
# "&" marks a reference to a passed block
|
# "&" marks a reference to a passed block
|
||||||
def guests(&block)
|
def guests(&block)
|
||||||
block.call 'some_argument'
|
block.call 'some_argument'
|
||||||
|
Loading…
Reference in New Issue
Block a user