Class: Typedocs::TypeSpec::HashValue
- Inherits:
-
Typedocs::TypeSpec
- Object
- Typedocs::TypeSpec
- Typedocs::TypeSpec::HashValue
- Defined in:
- lib/typedocs/type_spec.rb
Instance Method Summary collapse
-
#initialize(entries, accept_others) ⇒ HashValue
constructor
[key, spec]…
- #to_source ⇒ Object
- #valid?(obj) ⇒ Boolean
Methods inherited from Typedocs::TypeSpec
Constructor Details
#initialize(entries, accept_others) ⇒ HashValue
[key, spec]… ->
133 134 135 136 137 138 139 |
# File 'lib/typedocs/type_spec.rb', line 133 def initialize(entries, accept_others) entries.each do|k, s| Typedocs.ensure_klass(s, Typedocs::TypeSpec) end @entries = entries @accept_others = accept_others end |
Instance Method Details
#to_source ⇒ Object
145 146 147 |
# File 'lib/typedocs/type_spec.rb', line 145 def to_source "{#{@entries.map{|key,value| "#{key.inspect} => #{value.to_source}"}.join(', ')}#{@accept_others ? ', ...' : ''}}" end |
#valid?(obj) ⇒ Boolean
140 141 142 143 144 |
# File 'lib/typedocs/type_spec.rb', line 140 def valid?(obj) obj.is_a?(::Hash) && (@accept_others || @entries.size == obj.size) && @entries.all? {|key, spec| obj.has_key?(key) && spec.valid?(obj[key]) } end |