class Object
Public Class Methods
metaclass()
click to toggle source
# File lib/sugar-high/metaclass.rb, line 2 def self.metaclass class << self; self; end end
Public Instance Methods
any_kind_of?(*kinds)
click to toggle source
# File lib/sugar-high/kind_of.rb, line 9 def any_kind_of? *kinds kinds.all_kinds.each do |kind| return true if self.kind_of? kind end false end
get_methods(*types)
click to toggle source
# File lib/sugar-high/methods.rb, line 2 def get_methods *types types.inject([]) do |list, type| list << case type when :all get_methods(:private, :protected, :public) when :private, :protected, :public send :"#{type}_methods" end list.flatten end.flatten.uniq end
kind_of_label?()
click to toggle source
# File lib/sugar-high/kind_of.rb, line 23 def kind_of_label? self.any_kind_of? String, Symbol end
kind_of_number?()
click to toggle source
# File lib/sugar-high/kind_of.rb, line 27 def kind_of_number? self.any_kind_of? Numeric end
kind_of_symbol?()
click to toggle source
# File lib/sugar-high/kind_of.rb, line 32 def kind_of_symbol? self.any_kind_of? Symbols, Symbol end
kinda_file?()
click to toggle source
# File lib/sugar-high/kind_of.rb, line 5 def kinda_file? any_kind_of?(File, Dir) end
last_arg(default, *args)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/sugar-high/module.rb, line 10 def modules *module_names, &block module_names.flatten.each do |name| class_eval %Q{ module #{name.to_s.camelize} #{yield block if block} end } end end
nested_modules(*module_names, &block)
click to toggle source
# File lib/sugar-high/module.rb, line 20 def nested_modules *module_names, &block module_names.flatten.inject([]) do |res, name| res << %Q{ module #{name.to_s.camelize} #{yield block if block} end} end.flatten.join("\n") end
not_any_kind_of?(*kinds)
click to toggle source
# File lib/sugar-high/kind_of.rb, line 16 def not_any_kind_of? *kinds kinds.all_kinds.each do |kind| return false if self.kind_of? kind end true end
with(instance, *args, &block)
click to toggle source
# File lib/sugar-high/dsl.rb, line 2 def with(instance, *args, &block) instance.instance_exec(*args, &block) instance end