Tuesday, 12 March 2019

How to get the hash key and value in ruby?


How to get the hash value using hash key in ruby

a = {1=>"Active", -1=>"Inactive", 0=>"Under Review"} 

a[1] # 'Active'

a[-1] # 'Inactive'

a[0] # 'Under Review'


How to get the hash key using hash value in ruby 


a = {1=>"Active", -1=>"Inactive", 0=>"Under Review"} 

a.key('Active') #1

a.key('Inactive') #-1

a.key('Under Review') #0

No comments:

Post a Comment

Interactor in Rails

What is interactor? Interactor provides a common interface for performing complex user interactions An interactor is a simple, sin...