Class: Traitee::Dict
- Inherits:
-
Object
- Object
- Traitee::Dict
- Defined in:
- lib/traitee/dict.rb
Instance Method Summary collapse
- #<<(method) ⇒ Object
-
#aliases(methods, aliases) ⇒ Object
create aliases for selected methods as described in opts.
-
#exclusions(methods, exclusions) ⇒ Object
fetch only methods on included in except opts.
-
#initialize ⇒ Dict
constructor
A new instance of Dict.
- #methods_hash(options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Dict
Returns a new instance of Dict.
5 6 7 |
# File 'lib/traitee/dict.rb', line 5 def initialize @methods = Set.new end |
Instance Method Details
#<<(method) ⇒ Object
9 10 11 |
# File 'lib/traitee/dict.rb', line 9 def <<(method) @methods << method end |
#aliases(methods, aliases) ⇒ Object
create aliases for selected methods as described in opts
30 31 32 |
# File 'lib/traitee/dict.rb', line 30 def aliases(methods, aliases) Hash[methods.map { |method_name, _method| [(aliases.include?(method_name) ? aliases[method_name] : method_name), _method] }] end |
#exclusions(methods, exclusions) ⇒ Object
fetch only methods on included in except opts
25 26 27 |
# File 'lib/traitee/dict.rb', line 25 def exclusions(methods, exclusions) methods.select { |method_name, _| !exclusions.include?(method_name) } end |
#methods_hash(options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/traitee/dict.rb', line 13 def methods_hash( = {}) except = Array([:except]) aliases = .fetch :aliases, {} methods_hash = Hash[ @methods.map { |method| traitee_module, name = method; [name, traitee_module.instance_method(name)] } ] methods_hash = exclusions(methods_hash, except) aliases(methods_hash, aliases) end |