Top Level Namespace
Defined Under Namespace
Modules: HashWiaModule Classes: Hash, HashWia
Instance Method Summary collapse
-
#HashWia(klass = nil, opts = nil) ⇒ Object
to create Task::STATUS and Task.status HashWia self, :status do |opt|.
Instance Method Details
#HashWia(klass = nil, opts = nil) ⇒ Object
to create Task::STATUS and Task.status HashWia self, :status do |opt|
or just to get a hash HashWia do |opt|
opt.DONE d: 'Done'
# or
opt.set 'DONE', :d, 'Done'
end
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/hash_wia/class.rb', line 35 def HashWia klass = nil, opts = nil if block_given? hash = HashWia.new if klass.class == Hash opts = klass klass = nil end opts ||= {} named_opts = HashWia::NamedOptions.new hash do |constant, code, value| if opts[:constants] if klass klass.const_set "#{opts[:constants]}_#{constant}".upcase, code else raise "Host class not given (call as HashWia self, constants: ...)" end end end yield named_opts if opts[:method] klass.define_singleton_method(opts[:method]) { hash } end unless opts[:freeze] == false hash.freeze end hash else raise ArgumentError, 'Block not provided' end end |