-
-
Save igauravsehrawat/6720904 to your computer and use it in GitHub Desktop.
This file contains 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
dog.legs.walk! if dog.normal? | |
dog.hover_craft.hover! if dog.robot? |
This file contains 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
class Dog | |
def move! | |
legs.walk! | |
end | |
end | |
dog.move! |
This file contains 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
dog.legs.walk! |
This file contains 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
def sales_tax | |
return 0 if purchaser.exempt_from_taxes? | |
price * .10 | |
end | |
def car.brake | |
switch_on_brake_light | |
unless stopped? | |
slow_down | |
end | |
end |
This file contains 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
def self.import_from_csv(csv) | |
csv.each_line do |line| | |
if line["type"] == "distributer" | |
Document.new(line["foo"], line["retail_price"]) | |
else | |
Document.new(line["foo"], line["wholesale_price"]) | |
end | |
end | |
end |
This file contains 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
def self.import_line(line) | |
if line["type"] == "distributer" | |
Document.new(line["foo"], line["retail_price"]) | |
else | |
Document.new(line["foo"], line["wholesale_price"]) | |
end | |
end | |
def self.import_from_csv(csv) | |
csv.each_line do |line| | |
import_line(line) | |
end | |
end |
This file contains 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
def expiry_date | |
case plan_type | |
when 'subscription' then next_month | |
when 'prepaid' then never | |
end | |
end | |
def monthly_charge | |
case plan_type | |
when 'subscription' then 300 | |
when 'prepaid' then 0 | |
end | |
end | |
def charge_per_rental | |
case plan_type | |
when 'subscription' then 0 | |
when 'prepaid' then 100 | |
end | |
end |
This file contains 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
class SubscriptionPlan | |
attributes :expiration_date => never, :monthly_charge => 300, :charge_per_rental => 0 | |
end | |
class PrepaidPlan | |
attributes :expiration_date => never, :monthly_charge => 300, :charge_per_rental => 0 | |
end | |
def plan_type | |
case plan_type | |
when 'subscription' then SubscriptionPlan.new | |
when 'prepaid' then PrepaidPlan.new | |
end | |
end | |
def expiry_date | |
plan_type.expiry_date | |
end | |
def monthly_charge | |
plan_type.monthly_charge | |
end | |
def charge_per_rental | |
plan_type.charge_per_rental | |
end |
This file contains 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
if account.balance >= amount | |
account.deduct(amount) | |
else | |
raise NotEnoughBalance | |
end | |
class Account | |
def deduct(amount) | |
balance -= amount | |
end | |
end |
This file contains 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
account.deduct(amount) | |
class Account | |
def deduct(amount) | |
raise NotEnoughBalance unless balance >= amount | |
balance -= amount | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment