Created
March 28, 2020 20:18
-
-
Save rohitjoshixyz/96d24c206bdc9666c8a0c1314e55799f to your computer and use it in GitHub Desktop.
Code snippet for my blog: Be the better half
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
| 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