Module: SimpleColor::Mixin
- Included in:
- SimpleColor
- Defined in:
- lib/simplecolor.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.define_color_methods(klass, *methods, opts_from: nil, color_module: ColorWrapper) ⇒ Object
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/simplecolor.rb', line 180 def self.define_color_methods(klass, *methods, opts_from: nil, color_module: ColorWrapper) methods=color_module.instance_methods if methods.empty? methods.each do |m| klass.define_method m do |*args, **l_opts, &b| opts= opts_from ? opts_from.opts : self.opts opts=opts.merge(l_opts) color_module.instance_method(m).bind(self).call(*args, **opts, &b) end end end |
Instance Method Details
#mix_in(klass) ⇒ Object
198 199 200 |
# File 'lib/simplecolor.rb', line 198 def mix_in(klass) klass.send :include, mixin end |
#mix_in_string ⇒ Object
201 202 203 |
# File 'lib/simplecolor.rb', line 201 def mix_in_string mix_in(String) end |
#mixin(*methods) ⇒ Object
191 192 193 194 195 196 |
# File 'lib/simplecolor.rb', line 191 def mixin(*methods) klass=self Module.new do Mixin.define_color_methods(self, *methods, opts_from: klass) end end |