Error giving puts of a variable within the DEF

Asked

Viewed 64 times

0

Hello. I can’t 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

Puts @IP shows nothing

2 answers

0


0

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

Example

puts "IP: #{@ip}"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.