Class: Swagger::Schema::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/swagger/schema/util.rb

Class Method Summary collapse

Class Method Details

.try_hash(obj, name) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/swagger/schema/util.rb', line 5

def try_hash(obj, name)
  if obj.respond_to?(:"[]")
    obj[name] || obj[name.is_a?(Symbol) ? name.to_s : name.to_sym]
  elsif obj.respond_to?(name)
    obj.send(name)
  end
end

.try_hash_with_integer(obj, name) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/swagger/schema/util.rb', line 13

def try_hash_with_integer(obj, name)
  if obj.respond_to?(:"[]")
    obj[name.to_i] || obj[name.to_s] || obj[name.to_s.to_sym]
  elsif obj.respond_to?(name)
    obj.send(name)
  end
end