0
您可以在Ruby(可能使用Rails)中使用curried参数的方法吗?在Ruby中使用curried参数的别名
def say(name)
puts "Hi, I'm #{ name }"
end
alias_method :introduce_john, :say, "John"
introduce_john # puts "Hi, I'm John"
您可以在Ruby(可能使用Rails)中使用curried参数的方法吗?在Ruby中使用curried参数的别名
def say(name)
puts "Hi, I'm #{ name }"
end
alias_method :introduce_john, :say, "John"
introduce_john # puts "Hi, I'm John"
缺省情况下,却是很容易的创建一个:
class Object
def self.curried_alias_method(new, original, *pre_args)
define_method(new) do |*args|
send(original, *pre_args, *args)
end
end
end
用法:
class Foo
def say(name)
puts "Hi, I'm #{ name }"
end
curried_alias_method :introduce_john, :say, "John"
end
Foo.new.introduce_john
# prints "Hi, I'm John"
为什么downvote? –
你怎么能Currize那已经是一元的方法?你可以用什么方式Currize一种方法?返回值是什么类型? – sawa