This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example 1: | |
def get_addresses | |
addresses = User.includes(:address) | |
end | |
====================== | |
# Example 2: | |
Solution: We will call directly initialize method for getter and setter method. | |
class Greeting | |
def initialize(name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example 1: | |
class User | |
["active", "inactive","pending"].each do |method| | |
define_method "#{method}?" do | |
self.status == method | |
end | |
end | |
end | |
============================== | |
###Test Case |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [ | |
["B", "C", "Win"], ## b= 3 | |
["A", "B", "Win"], # a = 3 | |
["D", "C", "Loss"], # c = 3 | |
["C", "A", "Loss"], # a = 6 | |
["B", "D", "Win"], # b = 6 | |
["A", "D", "Draw"], ## a 7 , d = 1 | |
["A", "B", "Draw"], # a = 8, b = 7, c = 3 , d = 1 | |
] |