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
-
#arguments ⇒ Hash
readonly
Argument hash.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Object
(also: #super_init)
Create new instance.
- #inspect ⇒ String
- #to_s ⇒ String
Instance Attribute Details
#arguments ⇒ Hash (readonly)
Returns argument hash.
14 15 16 |
# File 'lib/krakow/utils/lazy.rb', line 14 def arguments @arguments end |
Instance Method Details
#initialize(args = {}) ⇒ Object 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 |
#inspect ⇒ String
45 46 47 |
# File 'lib/krakow/utils/lazy.rb', line 45 def inspect "<#{self.class.name}:#{object_id} [#{arguments.inspect}]>" end |
#to_s ⇒ String
40 41 42 |
# File 'lib/krakow/utils/lazy.rb', line 40 def to_s "<#{self.class.name}:#{object_id}>" end |