Class: SafeMe::NilableType

Inherits:
Object
  • Object
show all
Defined in:
lib/safe-me/nilable_type.rb

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ NilableType

Returns a new instance of NilableType.



3
4
5
# File 'lib/safe-me/nilable_type.rb', line 3

def initialize type
  @type = type
end

Instance Method Details

#to_sObject



11
12
13
# File 'lib/safe-me/nilable_type.rb', line 11

def to_s
  "#{@type} or nil"
end

#type_of?(obj) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/safe-me/nilable_type.rb', line 7

def type_of? obj
  obj.nil? or obj.kind_of?(@type)
end