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



184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/simplecolor.rb', line 184

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|
		klass.class_eval do
			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
end

Instance Method Details

#mix_in(klass) ⇒ Object



205
206
207
# File 'lib/simplecolor.rb', line 205

def mix_in(klass)
	klass.send :include, mixin
end

#mix_in_stringObject



208
209
210
# File 'lib/simplecolor.rb', line 208

def mix_in_string
	mix_in(String)
end

#mixin(*methods) ⇒ Object



198
199
200
201
202
203
# File 'lib/simplecolor.rb', line 198

def mixin(*methods)
	klass=self
	Module.new do
		Mixin.define_color_methods(self, *methods, opts_from: klass)
	end
end