Sha256: a1802f824254044b052a59121ca89a3184570447ee34a537f88eea573a1ba139

Contents?: true

Size: 583 Bytes

Versions: 1

Compression:

Stored size: 583 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

1 entries across 1 versions & 1 rubygems

Version Path
sc-core-ext-1.1.1 lib/sc-core-ext/object.rb