Sha256: 653ec77b2292319265307f1e45ec729c3a4b0728900b9393128e8fb34142e4ca

Contents?: true

Size: 612 Bytes

Versions: 5

Compression:

Stored size: 612 Bytes

Contents

require 'freighthopper/array/singular'
require 'freighthopper/string/unindent'

class Module  
  def antonym_accessor(*args)
    if 2 == args.length
      from, to = args
      define_method("#{to}?") { not send "#{from}?" }
      define_method("#{to}=") {|val| send "#{from}=", ! val }
    elsif args.singular.is_a?(Hash)
      args.singular.each {|from, to| antonym_accessor from, to}
    else
      message = <<-EXCEPTION
        antonym_accessor expects either
          "antonym_accessor :from, :to"
        or "antonym_accessor :from => :to"
      EXCEPTION

      raise message.unindent
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
freighthopper-0.1.14 lib/freighthopper/antonym_accessor.rb
freighthopper-0.1.13 lib/freighthopper/antonym_accessor.rb
freighthopper-0.1.12 lib/freighthopper/antonym_accessor.rb
freighthopper-0.1.11 lib/freighthopper/antonym_accessor.rb
freighthopper-0.1.9 lib/freighthopper/antonym_accessor.rb