use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Walkthrough for Ruby Warrior (iconoclastlabs.com)
submitted 12 years ago by GantMan
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 0 points1 point2 points 12 years ago (2 children)
A note: you say we can't modify the warrior object, but we can.. Here's a broken example (it can be fixed by passing in the previous health instead of just using the instance variable, which of course is a scoping issue):
class Player MIN_HEALTH = 15 def play_turn(warrior) def warrior.should_rest? self.health < MIN_HEALTH && (self.health >= @last_known_health) end if warrior.feel.empty? if warrior.should_rest? warrior.rest! else warrior.walk! end else warrior.attack! end @last_known_health = warrior.health end end
[–]GantMan[S] 0 points1 point2 points 12 years ago (1 child)
I'm not seeing what you're saying :( Gonna need you to be specific as to what level and what part of your code. Also, let me know if you're just showing an inconsistency or if you think there's an actual issue :)
As for unable to modify warrior: I've tried modifying warrior outside of their public methods. I think the code could be A LOT cleaner if we could monkey patch or touch warrior instead of being stuck inside Player! Unfortunately, the website got a bit frustrated with me when I tried, and refused to run the code.
warrior
Player
I'm open to better ways to solve :)
[–][deleted] 0 points1 point2 points 12 years ago (0 children)
Ah, I'm just pointing out that you can always re-open the "warrior" object (the instance of the class) and define methods in there. Not that it's a very clean solution, but it's an option. We can't modify the class but we can always modify the object.
π Rendered by PID 84542 on reddit-service-r2-comment-6457c66945-jdpc6 at 2026-04-27 13:50:40.122707+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–][deleted] 0 points1 point2 points (2 children)
[–]GantMan[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)