Class: Fixnum

Inherits:
Object
  • Object
show all
Defined in:
lib/1_as_identity_function.rb

Instance Method Summary collapse

Instance Method Details

#respond_to_with_1_as_identity_function?(name, include_private = false) ⇒ Boolean Also known as: respond_to?

Returns:

  • (Boolean)


8
9
10
11
12
13
14
# File 'lib/1_as_identity_function.rb', line 8

def respond_to_with_1_as_identity_function?(name, include_private = false)
  if name.to_s == 'to_proc'
    return self == 1
  else
    return respond_to_without_1_as_identity_function?(name, include_private)
  end
end

#to_procObject

Raises:

  • (NoMethodError)


4
5
6
7
# File 'lib/1_as_identity_function.rb', line 4

def to_proc
  raise NoMethodError unless self == 1
  lambda {|x| x}
end