x, y, z = 10, 20, 30 # parralel asignment

HackerRank

print self
# OUTPUT: main (if not in main exe)


# Variadic argument
def full_name(*rest)
    return rest.join(' ')
end


# Argument Hash
def fetch_file(uri, options)
    if options.has_key?(:proxy)

# do something
    end
end


# Argument Optional
def foo(x, str: "foo", num: 424242)
  [x, str, num]
end
foo(13)
#=> [13, 'foo', 424242]
foo(13, str: 'bar')
#=> [13, 'bar', 424242]


# Argument optional hash
def foo(str: "foo", num: 424242, **options)
  [str, num, options]
end
foo
#=> ['foo', 424242, {}]
foo(check: true)
# => ['foo', 424242, {check: true}]




Temperature conversion

Block

Proc

Lambda

Lambdas can be used as arguments to higher-order functions. They can also be used to construct the result of a higher-order function that needs to return a function.