Member-only story

Frequently used Active Support Methods in Ruby on Rails — Part 1

Gokul
2 min readOct 2, 2020

--

Ruby on rails

Active Support is the feature of Ruby on Rails which is responsible for providing utilities and extensions.

blank?

Returns true if the object in the following state,

false.blank?       # truenil.blank?         # true[].blank?          # true{}.blank?          # true"".blank?          # true''.blank?          # true'   '.blank?       # true

Example:

name = '''Guest' if name.blank?   # Guest

present?

Returns the true/false value. present? internally reuses the blank?. An object is present if it’s not blank.

name = 'Gokul'name if name.present?    # Gokul

presence

Returns the object/nil. The presence helps to get the value if the value present else will returns nil. It’s a good alternative to the conditional statement.

Example

name = ''
puts "Hi #{name.present? ? name : 'Guest'}" # Hi Guest
name = 'Gokul'
puts…

--

--

Gokul
Gokul

Responses (1)