Module: StructOpts
- Defined in:
- lib/common/struct_opts.rb
Overview
def foo opts = {}
@opts = StructOpts opts, foo: 123, bar: nil
...
Class Method Summary collapse
Class Method Details
.call(vars, opts) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/common/struct_opts.rb', line 8 def self.call vars, opts name = '%sStructOpts' % self.class struct = StructOpts::OPTS[name] ||= Struct.new name, *opts.keys ivars = struct.new vars.each do |k, v| ivars.send '%s=' % k, v end opts.each do |k, v| if vars[k].empty? ivars.send '%s=' % k, v end end ivars end |