分享 Ruby 支持这一的单行函数吗?

rehmet · December 03, 2012 · Last by Anleb replied at December 06, 2012 · 2503 hits

def add(a, b): return a+b 或者 twice = lambda x: x*2

def add(a, b); return a+b; end

但是没有必要这样写,不便于阅读 此外,还有这种

name = 1 if s = true

😃 谢谢,这个网站很不错。喜欢

#1 楼 @huacnlee #2 楼 @rehmet class_eval 的时候 会有这样的要求,写成一行代码

更多的则是:

A.class_eval <<-END
    def tell
        puts "ruby-china.org"
    end
END
You need to Sign in before reply, if you don't have an account, please Sign up first.