module Krakow::Utils::Lazy::InstanceMethods
Instance methods for laziness
Attributes
arguments[R]
@return [Hash] argument hash
Public Class Methods
new(args={})
click to toggle source
Create new instance
@param args [Hash] @return [Object]
# File lib/krakow/utils/lazy.rb, line 20 def initialize(args={}) @arguments = {}.tap do |hash| self.class.attributes.each do |name, options| val = args[name] if(options[:required] && !args.has_key?(name)) raise ArgumentError.new("Missing required option: `#{name}`") end if(val && options[:type] && !(valid = [options[:type]].flatten.compact).detect{|k| val.is_a?(k)}) raise TypeError.new("Invalid type for option `#{name}` (#{val} <#{val.class}>). Valid - #{valid.map(&:to_s).join(',')}") end if(val.nil? && options[:default] && !args.has_key?(name)) val = options[:default].respond_to?(:call) ? options[:default].call : options[:default] end hash[name] = val end end end
Public Instance Methods
inspect()
click to toggle source
@return [String]
# File lib/krakow/utils/lazy.rb, line 45 def inspect "<#{self.class.name}:#{object_id} [#{arguments.inspect}]>" end
to_s()
click to toggle source
@return [String]
# File lib/krakow/utils/lazy.rb, line 40 def to_s "<#{self.class.name}:#{object_id}>" end