if statements that also use .include? and && in ruby -


I'm new to Ruby and I'm trying to create a little zoric game. I'm having trouble in the following lines of code: action action "get action" = get.chomp if action.include? 'Look' and amp; Amp; 'Bed' puts "you look at the bed" Elsph action.include? 'Pickup' & amp; Amp;

For some reasons when I first type it in a new file it will work. If I change the code in any way, it only gives me the first time.

You can do monkey patch string to do something < Pre> contains class string DRF? (* Args) args.map {| Arg |

then call

  action = "Look at a dog bed for sale" Action.include_all? ("Watch", "bed") # => True action.include_all? ("Watch", "bed", "fish") # => False   

It takes many of the arguments you provide and keeps them using a array by splat * . To see if every one is included in a string , then it reduces a single value by using the and operator, so that it

  action = "see a dog bed for sale" action.include_all ("look", "bed") #args = ["look", "bed"] # args.map {| Arg | Action.include? (Arg)} # = & gt; [True, true] # truth & amp; True # = & gt; # Action.Include_all ("look", "bed", "fish") #args = ["look", "bed", "fish"] # args.map {| Arg | Action.include? (Arg)} # = & gt; [True, true, false] #hoot & amp; True & amp; False # = & gt; Incorrect   

Other suggestions are a more standard process. I only tell new Rubyists that changing one class is a very simple process. Use at your own risk

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -