Class: Hako::Schema::WithDefault
- Inherits:
-
Object
- Object
- Hako::Schema::WithDefault
- Defined in:
- lib/hako/schema/with_default.rb
Instance Method Summary collapse
-
#initialize(schema, default) ⇒ WithDefault
constructor
A new instance of WithDefault.
- #same?(x, y) ⇒ Boolean
- #valid?(object) ⇒ Boolean
- #wrap(x) ⇒ Object private
Constructor Details
#initialize(schema, default) ⇒ WithDefault
Returns a new instance of WithDefault.
6 7 8 9 |
# File 'lib/hako/schema/with_default.rb', line 6 def initialize(schema, default) @schema = schema @default = default end |
Instance Method Details
#same?(x, y) ⇒ Boolean
15 16 17 |
# File 'lib/hako/schema/with_default.rb', line 15 def same?(x, y) @schema.same?(wrap(x), wrap(y)) end |
#valid?(object) ⇒ Boolean
11 12 13 |
# File 'lib/hako/schema/with_default.rb', line 11 def valid?(object) object.nil? || @schema.valid?(object) end |
#wrap(x) ⇒ Object (private)
21 22 23 |
# File 'lib/hako/schema/with_default.rb', line 21 def wrap(x) x.nil? ? @default : x end |