1
我在Ruby中为String类添加了一个新方法,如何获取该类的值?在String类中获取字符串值
例如为:
class String
def myMethodName(arguments)
# here I want the string value
end
end
puts "Lennie".myMethodName()
# this should return "Lennie" or whatever the value of the string is.
感谢
首先,你不需要在Ruby中使用空的参数括号。他们是可选的。其次,方法名称通常被强调,而不是骆驼式的。 – 2009-03-03 03:57:30