Skip to content

Instantly share code, notes, and snippets.

@rohitjoshixyz
Created March 28, 2020 20:18
Show Gist options
  • Select an option

  • Save rohitjoshixyz/96d24c206bdc9666c8a0c1314e55799f to your computer and use it in GitHub Desktop.

Select an option

Save rohitjoshixyz/96d24c206bdc9666c8a0c1314e55799f to your computer and use it in GitHub Desktop.
Code snippet for my blog: Be the better half
require 'opportunity_ships.rb'
def achieve_goal(aim, ship)
raise "Failure is not a crime, having a low aim is..." if aim.low?
unless aim.achieved? do
new_ship = choose_right_ship(ship)
if better_half?(new_ship)
change_ship(ship,new_ship)
else
struggle_and_hustle
end
end
end
choose_right_ship(self)
opportunities.each do |opportunity|
if opportunity.type == self.interest
opportunity.get_ship
end
end
end
def better_half?(self, ship)
self > ship.crew / 2 ? true : false # in top 50%
end
def change_ship(old_ship, new_ship)
new_ship.class in ship.descendants() ? new_ship : old_ship #specialization
end
def struggle_and_hustle
# This is domain specific and to be implemented by end user
# Or it will be the developer who will achieve the goal instead
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment