Class: Dmm::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dmm/base.rb

Direct Known Subclasses

Item, Iteminfo, Price, Response, Result

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Base

Initializes a new object

Parameters:

  • attrs (Hash) (defaults to: {})


21
22
23
# File 'lib/dmm/base.rb', line 21

def initialize(attrs={})
  @attrs = attrs
end

Class Method Details

.attr_reader(*attrs) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dmm/base.rb', line 3

def self.attr_reader(*attrs)
  mod = Module.new do
    attrs.each do |attribute|
      define_method attribute do
        @attrs[attribute.to_sym]
      end
      define_method "#{attribute}?" do
        !!@attribute[attribute.to_sym]
      end
    end
  end
  const_set(:Attributes, mod)
  include mod
end