Class: BBLib::HashStruct
Method Summary
Methods inherited from Hash
#deep_merge, #deep_merge!, #diff, #dive, #except, #expand, #hash_path, #hash_path_copy, #hash_path_copy_to, #hash_path_delete, #hash_path_for, #hash_path_move, #hash_path_move_to, #hash_path_proc, #hash_path_set, #hash_paths, #hmap, #keys_to_s, #keys_to_s!, #keys_to_sym, #keys_to_sym!, #kmap, #only, #path_hash, #path_nav, #reverse, #reverse!, #squish, #to_tree_hash, #unshift, #vmap
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (protected)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hash/hash_struct.rb', line 8 def method_missing(method, *args, &block) if args.empty? && ![:to_ary].include?(method) define_singleton_method(method) do self[method] end self[method] elsif method.to_s.end_with?('=') define_singleton_method(method) do |arg| self[method[0..-2].to_sym] = arg end self[method[0..-2].to_sym] = args.first else super end end |