Notes posted by sselvamani22
RSS feed
0 thanks
association our data
we can load our data whenever we want.
ActiveRecord::Associations::Preloader.new.preload(@users, :company)

0 thanks
Preload our own with out incude
we can preload our data whenever we want.
ActiveRecord::Associations::Preloader.new.preload(@users, :address)

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)

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"