Error when putting puts of a variable within the DEF

0

Hello. I can not print variable that is inside a def.

Script

class LogParser

def initialize (ip, data, code)

log = File.open("/project/log_sec/log/log.txt").each do |file|
  parse = file.split(" ")
  data = parse[0] 
  time = parse[1]
  @ip = parse[2]
  method = parse[3]
  url = parse[4]
  code = parse[5]
  ref = parse[8]
  useragent = parse[9]    
end

end

def displayparse ()

puts "IP #@ip"

end

The @IP puts nothing appears

    
asked by anonymous 18.11.2015 / 19:39

2 answers

0

ThefunctionalitythattransformsaStringintoanArrayiscalled

to_a
ApiDock documentation on to_a     
18.11.2015 / 21:03
0

Use "# {@ variavel}" whenever you want to print a "

Example

puts "IP: #{@ip}"
    
17.12.2015 / 15:02