Notes posted by sselvamani22
RSS feed
sselvamani22 -
February 1, 2017 - (v4.1.8 - v4.2.7)
0 thanks
association our data
we can load our data whenever we want.
ActiveRecord::Associations::Preloader.new.preload(@users, :company)
sselvamani22 -
February 1, 2017 - (v4.1.8 - v4.2.7)
0 thanks
Preload our own with out incude
we can preload our data whenever we want.
ActiveRecord::Associations::Preloader.new.preload(@users, :address)
sselvamani22 -
February 12, 2016
0 thanks
group on hash
‘
def group_by_hash hash, value hash.group_by do |k,v| v > value ? "Big" : "Small" end end marks = {"Chair" => 30, "Table" => 40, "Bed" => 60, "stool" => 20} group_by_hash(marks, 30)
sselvamani22 -
August 18, 2015
0 thanks
Add method to instacne eval
We can add method to instance by using instance_eval.
Code example
string = "String" string.instance_eval do def new_method self.reverse end end
Output
irb(main):033:0> string.new_method => "gnirtS"