Module: AttrExtras::AttrQuery

Defined in:
lib/attr_extras/attr_query.rb

Class Method Summary collapse

Class Method Details

.define_with_suffix(klass, suffix, *names) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
# File 'lib/attr_extras/attr_query.rb', line 2

def self.define_with_suffix(klass, suffix, *names)
  names.each do |name|
    name = name.to_s

    raise ArgumentError, "#{__method__} wants `#{name}?`, not `#{name}`." unless name.end_with?("?")

    klass.send(:define_method, name) do  # def foo?
      !!send("#{name.chop}#{suffix}")    #   !!send("foo_id")
    end                                  # end
  end
end