Sha256: 270c53e31f992a400d5d89c886f810007726342cf3afc7846e715e26f168eb90
Contents?: true
Size: 910 Bytes
Versions: 1
Compression:
Stored size: 910 Bytes
Contents
require "attr_extras/version" module AttrExtras module ClassMethods def attr_initialize(*names) define_method(:initialize) do |*values| unless values.length == names.length raise ArgumentError, "wrong number of arguments (#{values.length} for #{names.length})" end names.zip(values).each do |name, value| instance_variable_set("@#{name}", value) end end end def attr_private(*names) attr_reader *names private *names end def attr_id_query(*names) names.each do |name| name = name.to_s raise "#{__method__} wants `#{name}?`, not `#{name}`." unless name.end_with?("?") define_method(name) do # def foo? !!send("#{name.chop}_id") # !!send("foo_id") end # end end end end end Object.extend AttrExtras::ClassMethods
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
attr_extras-1.0.0 | lib/attr_extras.rb |