这个功能要模拟Groovy中Expando和Javascript中的{},这里要用到ruby自带的osstruct库
#!C:/Ruby192/bin/ruby.exe
require 'ostruct'
def mytest
puts "a method"
end
o = OpenStruct.new
o.method1 = mytest
o.prop1 = "a property"
puts o.method1
puts o.prop1
这个功能要模拟Groovy中Expando和Javascript中的{},这里要用到ruby自带的osstruct库
#!C:/Ruby192/bin/ruby.exe
require 'ostruct'
def mytest
puts "a method"
end
o = OpenStruct.new
o.method1 = mytest
o.prop1 = "a property"
puts o.method1
puts o.prop1
转载于:https://www.cnblogs.com/buhaiqing/archive/2012/12/18/2822625.html