Module: Krakow::Utils::Lazy::InstanceMethods
- Included in:
- Distribution, FrameType, Producer::Http
- Defined in:
- lib/krakow/utils/lazy.rb
Overview
Instance methods for laziness
Instance Attribute Summary (collapse)
-
- (Hash) arguments
readonly
Argument hash.
Instance Method Summary (collapse)
-
- (Object) initialize(args = {})
(also: #super_init)
Create new instance.
- - (String) inspect
- - (String) to_s
Instance Attribute Details
- (Hash) arguments (readonly)
Returns argument hash
14 15 16 |
# File 'lib/krakow/utils/lazy.rb', line 14 def arguments @arguments end |
Instance Method Details
- (Object) initialize(args = {}) Also known as: super_init
Create new instance
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/krakow/utils/lazy.rb', line 20 def initialize(args={}) @arguments = {}.tap do |hash| self.class.attributes.each do |name, | val = args[name] if([:required] && !args.has_key?(name)) raise ArgumentError.new("Missing required option: `#{name}`") end if(val && [:type] && !(valid = [[: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? && [:default] && !args.has_key?(name)) val = [:default].respond_to?(:call) ? [:default].call : [:default] end hash[name] = val end end end |
- (String) inspect
45 46 47 |
# File 'lib/krakow/utils/lazy.rb', line 45 def inspect "<#{self.class.name}:#{object_id} [#{arguments.inspect}]>" end |
- (String) to_s
40 41 42 |
# File 'lib/krakow/utils/lazy.rb', line 40 def to_s "<#{self.class.name}:#{object_id}>" end |