what am i doing wrong? `class twelvedays def self.song = p file.open('ruby/twelve-days/song.txt', "r").read end` in ruby

The code you provided has a few syntax errors. Here's the corrected version:

main.rb
class Twelvedays
  def self.song
    file = File.open('ruby/twelve-days/song.txt', "r")
    file.read
  end
end
112 chars
7 lines

Here's what's changed:

  • The class name "twelvedays" has been capitalized as "Twelvedays", following Ruby's naming conventions.
  • The method assignment operator should be "=" instead of "= p". So, def self.song = p file.open('ruby/twelve-days/song.txt', "r").read end should be def self.song.
  • The file opening statement has been corrected by assigning the File.open method to the variable file.
  • To read the contents of the file, you can call the read method on the file object.

Please note that you need to make sure the path 'ruby/twelve-days/song.txt' is correct for the file you want to read.

related categories

gistlibby LogSnag