Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/sc-core-ext/object.rb
Class Method Summary collapse
-
.attr_boolean(*a) ⇒ Object
Creates an attribute accessor similar to attr_accessor, except the reader is appended with a question mark.
Instance Method Summary collapse
-
#dup? ⇒ Boolean
Attempts to call #dup, and returns itself if the object cannot be duped (Symbol, Fixnum, etc.).
Class Method Details
.attr_boolean(*a) ⇒ Object
Creates an attribute accessor similar to attr_accessor, except the reader is appended with a question mark. The variable name is the same.
Example:
attr_boolean :new_record # => { #new_record=(bool), #new_record? }
14 15 16 17 |
# File 'lib/sc-core-ext/object.rb', line 14 def attr_boolean(*a) attr_writer *a a.each { |i| define_method("#{i}?") { instance_variable_get("@#{i}") } } end |
Instance Method Details
#dup? ⇒ Boolean
Attempts to call #dup, and returns itself if the object cannot be duped (Symbol, Fixnum, etc.)
3 4 5 |
# File 'lib/sc-core-ext/object.rb', line 3 def dup? dup rescue self end |