Module: Kernel
- Defined in:
- lib/guerrilla_patch/kernel.rb,
lib/guerrilla_patch/kernel.rb,
lib/guerrilla_patch/string.rb
Defined Under Namespace
Classes: PoorsManStringBuilder
Instance Method Summary
collapse
Instance Method Details
#allocate(ratios) ⇒ Object
114
115
116
|
# File 'lib/guerrilla_patch/kernel.rb', line 114
def allocate(ratios)
Allocate.new(self.to_d, ratios).divided
end
|
#allocate_evenly(number_of_slices) ⇒ Object
110
111
112
|
# File 'lib/guerrilla_patch/kernel.rb', line 110
def allocate_evenly(number_of_slices)
Allocate.evenly(self.to_d, number_of_slices)
end
|
#auto_assign(caller_binding) ⇒ Object
5
6
7
|
# File 'lib/guerrilla_patch/kernel.rb', line 5
def auto_assign(caller_binding)
method(caller[0][/`.*'/][1..-2]).parameters.each { |arg| instance_eval("@#{arg[1]} = caller_binding.eval(arg[1].to_s)") }
end
|
#consists_of ⇒ Object
25
26
27
|
# File 'lib/guerrilla_patch/kernel.rb', line 25
def consists_of
PoorsManStringBuilder.new.tap { |builder| yield(builder) }.result
end
|
#let(name, &block) ⇒ Object
9
10
11
|
# File 'lib/guerrilla_patch/kernel.rb', line 9
def let(name, &block)
define_method(name, &block)
end
|
#let_self(name, &block) ⇒ Object
13
14
15
|
# File 'lib/guerrilla_patch/kernel.rb', line 13
def let_self(name, &block)
define_singleton_method(name, &block)
end
|
#plural(item) ⇒ Object
37
|
# File 'lib/guerrilla_patch/string.rb', line 37
def plural(item) item.count > 1 ? 's' : '' end
|
106
107
108
|
# File 'lib/guerrilla_patch/kernel.rb', line 106
def to_d
BigDecimal.new(self.to_s)
end
|
#when_present(item, &block) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/guerrilla_patch/kernel.rb', line 17
def when_present(item, &block)
if block_given?
item.nil? ? '' : block.call(item)
else
item
end
end
|