Call method from parameter : Method Arguments « Method « Ruby






Call method from parameter


def endless_string_succession(start)
  while true
    yield start
    start = start.succ
  end
end

endless_string_succession('fol') do |x|
  puts x
  break if x[-1] == x[-2]
end
# fol
# fom
# fon
# foo

 








Related examples in the same category

1.Passing Arguments to a Method
2.The parentheses in the call are optional
3.Passing Data to Methods with or without parenthesis
4.Function with two parameters
5.Method with three parameters
6.Pass full arrays to methods in Ruby, and return arrays as well
7.Default Arguments
8.Writing a Method that Accepts a Block
9.Block as the third parameter
10.Raise exception based on parameter type
11.raise ArgumentError