Class: NakoPay::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/nakopay/resource.rb

Overview

Lightweight wrapper that lets callers do ‘inv.id` instead of `inv`.

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Resource

Returns a new instance of Resource.



4
5
6
# File 'lib/nakopay/resource.rb', line 4

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &blk) ⇒ Object



16
17
18
19
20
21
# File 'lib/nakopay/resource.rb', line 16

def method_missing(name, *args, &blk)
  key = name.to_s
  return @attrs[key] if @attrs.key?(key)

  super
end

Instance Method Details

#[](key) ⇒ Object



8
# File 'lib/nakopay/resource.rb', line 8

def [](key) = @attrs[key.to_s]

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/nakopay/resource.rb', line 12

def respond_to_missing?(name, include_private = false)
  @attrs.key?(name.to_s) || super
end

#to_hObject



9
# File 'lib/nakopay/resource.rb', line 9

def to_h = @attrs.dup

#to_jsonObject



10
# File 'lib/nakopay/resource.rb', line 10

def to_json(*) = @attrs.to_json