Module: Term::Colorizer::InstanceMethods
- Defined in:
- lib/term-colorizer/colorizer.rb
Instance Method Summary collapse
-
#color_methods ⇒ Object
returns array of available color methods.
-
#method_missing(method, *args, &block) ⇒ Object
overriden method_missing’s default behaviour to define the color methods on the fly when called.
-
#respond_to_missing?(method, include_private = false) ⇒ Boolean
overriden respond_to? so as to it will return true when asked for any of available color methods.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
overriden method_missing’s default behaviour to define the color methods on the fly when called
32 33 34 35 36 37 |
# File 'lib/term-colorizer/colorizer.rb', line 32 def method_missing(method, *args, &block) #:nodoc: super unless TERM_COLORS.keys.include? method self.class.send(:define_method, method) do TERM_COLORS[method].sub(/STR/, self.to_s) end and self.send(method, *args) end |
Instance Method Details
#color_methods ⇒ Object
returns array of available color methods
26 27 28 |
# File 'lib/term-colorizer/colorizer.rb', line 26 def color_methods TERM_COLORS.keys end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
overriden respond_to? so as to it will return true when asked for any of available color methods
41 42 43 |
# File 'lib/term-colorizer/colorizer.rb', line 41 def respond_to_missing?(method, include_private = false) #:nodoc: TERM_COLORS.keys.include? method || super end |