Class: NilClass

Inherits:
Object show all
Defined in:
lib/ruby/jruby_hack.rb,
lib/ruby/jruby_hack.rb

Combinators collapse

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Always ‘true`. Note this overrides Object#blank? which returns false.

Examples:

nil.blank?    #=> true

Returns:

  • (Boolean)


250
251
252
# File 'lib/ruby/jruby_hack.rb', line 250

def blank?
  true
end

#present?Boolean

Returns:

  • (Boolean)


254
255
256
# File 'lib/ruby/jruby_hack.rb', line 254

def present?
  false
end

#try(*args) ⇒ Object

Returns ‘nil` (when `self` is `nil`). This overrides Object#try

Examples:

"non-nil".try(&:length) #=> 7
nil.try(&:length)       #=> nil

"non-nil".try(:slice, 0, 3)   #=> "non"
nil.try(:slice, 0, 3)         #=> nil

Returns:

  • nil



680
681
682
# File 'lib/ruby/jruby_hack.rb', line 680

def try(*args)
  self
end