Class: NRSER::Types::Attrs
Instance Method Summary collapse
- #default_name ⇒ Object
-
#initialize(attrs, **options) ⇒ Attrs
constructor
A new instance of Attrs.
- #test(value) ⇒ Object
Methods inherited from Type
#check, #from_s, #has_from_s?, #name, #respond_to?, short_name, #to_s
Constructor Details
#initialize(attrs, **options) ⇒ Attrs
Returns a new instance of Attrs.
9 10 11 12 |
# File 'lib/nrser/types/attrs.rb', line 9 def initialize attrs, ** super ** @attrs = attrs end |
Instance Method Details
#default_name ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/nrser/types/attrs.rb', line 14 def default_name attrs_str = @attrs.map {|name, type| "#{ name }=#{ type.name }" }.join(', ') "#{ self.class.short_name }(#{ attrs_str })" end |
#test(value) ⇒ Object
22 23 24 25 26 |
# File 'lib/nrser/types/attrs.rb', line 22 def test value @attrs.all? {|name, type| value.respond_to?(name) && type.test(value.method(name).call) } end |