RosettaCodeData/Task/Function-composition/Ruby/function-composition.rb

9 lines
187 B
Ruby
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
def compose(f,g)
lambda {|x| f[g[x]]}
end
s = compose(Math.method(:sin), Math.method(:cos))
p s[0.5] # => 0.769196354841008
# verify
p Math.sin(Math.cos(0.5)) # => 0.769196354841008