Nathan Viswa wrote:
> when i enter nil for gets, it is not comparing with another string
> having nil value.
> 

How did you enter nil for gets?


> tried gets.chomp which also gives the same problem.
> 
> any help?
>
> #party = gets.chomp  #  nil fails
> 
> if party != nil
>   democrats.each { |i| print i, " "} if party == "democrats"
>   puts 'x5'
>   republicans.each { |i| print i, " "} if party == "republicans"
>   puts 'x6'
>   print "All presidents since 1976 were either Democrats or
> Republicans\n"\
>       if (party != "democrats" && party != "republicans")
> end


input = "nil\n"
input = input.chomp
puts input.class   #String

some_var = nil
puts some_var.class   #NilClass

if input == some_var
  puts "The user entered the ruby nil object."
else
  puts "The user didn't enter the ruby nil object."
end

--output:--
The user didn't enter the ruby nil object.

some_var = 'nil'

if input == some_var
  puts "The user entered a string containing the characters n, i, and 
l."
else
  puts "The user didn't enter a string containing the charcters n, i, 
and l."end

--output:--
The user entered a string containing the characters n, i, and l.


-- 
Posted via http://www.ruby-forum.com/.