How can I access a variable defined in a Ruby file I required in IRB?

前端 未结 4 1679
囚心锁ツ
囚心锁ツ 2020-12-01 18:33

The file welcome.rb contains:

welcome_message = \"hi there\"

But in IRB, I can\'t access the variable I just created:

4条回答
  •  天命终不由人
    2020-12-01 19:06

    I think the best way is to define a class like this

    class Welcome
      MESSAGE = "hi there"
    end
    

    then in irb you can call your code like this :

    puts Welcome::MESSAGE
    

提交回复
热议问题