Top Level Namespace
Defined Under Namespace
Modules: Enumerable, FilesArray, Math, MathArray, NumberDslExt, NumericCheckExt, PathString, Properties, RSpec, SugarHigh
Classes: Array, Boolean, DelegateDecorator, FalseClass, File, Hash, Kinds, MatchData, Module, NilClass, Object, Range, Regexp, String, Symbol, TrueClass
Instance Method Summary
collapse
Instance Method Details
#last_arg(default, *args) ⇒ Object
44
45
46
47
|
# File 'lib/sugar-high/arguments.rb', line 44
def last_arg default, *args
last = args.flatten.last
last.kind_of?(Hash) ? last : default
end
|
#last_arg_value(default, *args) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/sugar-high/arguments.rb', line 49
def last_arg_value default, *args
last = args.flatten.last
raise ArgumentError, "Default value must be a Hash, was #{default}" if !default.kind_of? Hash
key = default.keys.first
return default[key] if !last.kind_of? Hash
last[key] ? last[key] : default[key]
end
|
#last_option(*args) ⇒ Object
38
39
40
41
42
|
# File 'lib/sugar-high/arguments.rb', line 38
def last_option *args
default = last_arg({}, *args)
last = args.flatten.last
last.kind_of?(Hash) ? last : default
end
|
#modules(*module_names, &block) ⇒ Object
10
11
12
13
14
15
16
17
18
|
# File 'lib/sugar-high/module.rb', line 10
def modules *module_names, &block
module_names.flatten.each do |name|
class_eval %{
module #{name.to_s.camelize}
#{yield block if block}
end
}
end
end
|
#nested_modules(*module_names, &block) ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/sugar-high/module.rb', line 20
def nested_modules *module_names, &block
module_names.flatten.inject([]) do |res, name|
res << %{
module #{name.to_s.camelize}
#{yield block if block}
end}
end.flatten.join("\n")
end
|