Output the function to a file

Trying to call a function and output the values to new file ? I am
missing something here

def get_status(wip)
puts “output is great”
end

File.open(’/tmp/net.out’, ‘w’) do |f|
f << get_status(“wip”)
end

or use p() :

p “output is great”

Satish Kumar wrote in post #1168658:

Trying to call a function and output the values to new file ? I am
missing something here

def get_status(wip)

#puts is the problem. It returns nil.

2.1.2 :001 > puts “hi”
hi
=> nil

puts “output is great”
end

File.open(’/tmp/net.out’, ‘w’) do |f|

That’s why your method #get_status returning nil, and which is getting
converted into to “”, due to the NilClass#to_s method.

f << get_status(“wip”)
end

Modify the method :

def get_status(wip)
“output is great”
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs