Way to read methods instead of instance variables
Opened this issue · 0 comments
evanthegrayt commented
Instead of directly reading an ivar, maybe users would want to read directly from a method.
Just spitballing without thinking through fully... but something like this?
class Person
extend Attribool
bool_reader :full_name, from_method: true
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
def full_name
return unless @first_name && @last_name
"#{@first_name} #{@last_name}"
end
end
p = Person.new(nil, nil)
p.full_name?
# false