Sha256: 36fa8c7da9f4b9386641a790543d38d338f16121b03fe0a86d3da4c153a76850

Contents?: true

Size: 564 Bytes

Versions: 2

Compression:

Stored size: 564 Bytes

Contents

class Object
  # Attempts to call #dup, and returns itself if the object cannot be duped (Symbol, Fixnum, etc.)
  def dup?
    dup rescue self
  end

  class << self
    # 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? }
    #
    def attr_boolean(*a)
      attr_writer *a
      a.each { |i| define_method("#{i}?") { instance_variable_get("@#{i}") } }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sc-core-ext-1.2.1 lib/sc-core-ext/object.rb
sc-core-ext-1.2.0 lib/sc-core-ext/object.rb