Class: InquiryAttrs::NilInquiry
- Inherits:
-
Object
- Object
- InquiryAttrs::NilInquiry
show all
- Defined in:
- lib/inquiry_attrs/nil_inquiry.rb
Overview
Returned by an inquired attribute when its raw value is blank.
Every ? predicate returns false, so callers never receive a
NoMethodError and nil comparisons work naturally.
user.status user.status.nil? user.status.active? user.status == nil
Constant Summary
collapse
- INSTANCE =
new.freeze
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *_args, &_block) ⇒ Object
Any ? method returns false — no NoMethodError on blank attributes.
18
19
20
21
22
|
# File 'lib/inquiry_attrs/nil_inquiry.rb', line 18
def method_missing(method_name, *_args, &_block)
return false if method_name.to_s.end_with?('?')
super
end
|
Instance Method Details
#==(other) ⇒ Object
42
43
44
|
# File 'lib/inquiry_attrs/nil_inquiry.rb', line 42
def ==(other)
other.nil? || other == '' || other.equal?(INSTANCE)
end
|
#blank? ⇒ Boolean
35
|
# File 'lib/inquiry_attrs/nil_inquiry.rb', line 35
def blank? = true
|
#empty? ⇒ Boolean
36
|
# File 'lib/inquiry_attrs/nil_inquiry.rb', line 36
def empty? = true
|
#inspect ⇒ Object
40
|
# File 'lib/inquiry_attrs/nil_inquiry.rb', line 40
def inspect = 'nil'
|
#is_a?(klass) ⇒ Boolean
Also known as:
kind_of?, instance_of?
NilClass cannot be subclassed in Ruby, so we override the type-check
methods explicitly — the same technique used by SymbolInquiry for Symbol.
30
|
# File 'lib/inquiry_attrs/nil_inquiry.rb', line 30
def is_a?(klass) = klass == NilClass || super
|
#nil? ⇒ Boolean
34
|
# File 'lib/inquiry_attrs/nil_inquiry.rb', line 34
def nil? = true
|
#present? ⇒ Boolean
37
|
# File 'lib/inquiry_attrs/nil_inquiry.rb', line 37
def present? = false
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
24
25
26
|
# File 'lib/inquiry_attrs/nil_inquiry.rb', line 24
def respond_to_missing?(method_name, include_private = false)
method_name.to_s.end_with?('?') || super
end
|
#to_s ⇒ Object
38
|
# File 'lib/inquiry_attrs/nil_inquiry.rb', line 38
def to_s = ''
|
#to_str ⇒ Object
39
|
# File 'lib/inquiry_attrs/nil_inquiry.rb', line 39
def to_str = ''
|