-4

Today I was given a correct solution. I ran it beautifully in IRB and it interprets is perfectly. However if I paste that code in a ide and then I call the program from the console, it shows nothing, although it runs. If I add a puts to see something just before the boolean code it lists me true false etc but nothing like the IRB intepreter, which actually gives the words in one array that are contained in the phrases of the other array.

This is clearly saying I have a mind-bogging ignorance about how in heaven's name this works. It is as if the IDE did not interpret anything, so I went from Komodo and installed Rubymine and installed the ruby interpreter that the IDE would work with. No difference.

I have copied and pasted the code in the Tutorialspoint and got this permalink that shows live what happens. Can anyone tell me how I should do to get the IDE just do what the IRB does

http://tpcg.io/HYfIrX

the code is this anyway

words = ["house", "dog", "cat", "man", "girl"]
phrases = ["I have a house", "I am a dog", "I am man"]

words.select { |word| phrases.any? { |phrase| phrase.include? word } }

THIS IS WHAT IS SHOWN IN THE IRB IT IS FINE AND THAT IS WHAT I WANT

root@kali:~/rubyprograms# irb
irb(main):001:0> words = ["house", "dog", "cat", "man", "girl"]
=> ["house", "dog", "cat", "man", "girl"]
irb(main):002:0> phrases = ["I have a house", "I am a dog", "I am man"]
=> ["I have a house", "I am a dog", "I am man"]
irb(main):003:0> 
irb(main):004:0* words.select { |word| phrases.any? { |phrase| phrase.include? word } }
=> ["house", "dog", "man"]

BUT IF YOU RUN THE SAME CODE (EXCEPT FOR A "PUTS" THAT I ADDED TO SEE SOMETHING" IT DOES NOT BRING AT ALL WHAT I WANT BUT A ROSTER OF BOOLEAN VALUES

http://tpcg.io/HYfIrX

Arminius
  • 606
  • 1
  • 6
  • 19
  • 1
    Please don't write ENTIRELY IN CAPITAL LETTERS, that's extremely hard to read, *not* how English works, and generally interpreted as very rude. – user229044 Oct 06 '17 at 17:06
  • IRB shows you the result of each expression, while your code doesn't **output** anything. If you want to see output, you need to do something with the results your code is generating, like `puts` it to the screen. – user229044 Oct 06 '17 at 17:12

1 Answers1

1

The link in your code is

words.select { |word| puts phrases.any? { |phrase| phrase.include? word } }

The correct code stated in your question (which works is)

words.select { |word| phrases.any? { |phrase| phrase.include? word } }

Spot the difference:)

Sagar Pandya
  • 9,323
  • 2
  • 24
  • 35
  • no, no, I know I added puts, which I did to see some result. If you go to the link where the code active is in Tutorials point you will see that it does not bring results check it, live http://tpcg.io/HYfIrX if you mistrust the link there are tools online that tell you the final link. This is a short href like it is common today remove the puts yourself and you will see that nothing is shown, That is actually my question, why? – Arminius Oct 06 '17 at 16:58
  • 1
    @Arminius write `p words.select { |word| phrases.any? { |phrase| phrase.include? word } }`. Ruby won't print your return value unless you tell it to do so. In this case use `p` to print the array. IRB automatically prints return values by default. ` – Sagar Pandya Oct 06 '17 at 17:13