无法将ruby文件从桌面加载到irb

时间:2014-09-13 00:39:18

标签: ruby terminal irb

我正在使用Ruby中的一个小应用程序。该文件名为“cookbook.rb”,它保存在我的Mac桌面上。

首先我输入

cd desktop 

将我带入桌面,然后我尝试加载文件,以便我可以在irb中查看它。我输入这个:

load 'cookbook.rb'

我一直收到这个错误:

SyntaxError: cookbook.rb:11: syntax error, unexpected keyword_end, expecting end-of-input
from (irb):1:in `load'
from (irb):1
from /usr/bin/irb:12:in `<main>'

有人可以告诉我我做错了什么吗?我遵循了我曾经创建和处理另一个.rb文件的相同指示,之前它运行得很好。

很抱歉这里有混淆......这里是文件cookbook.rb

 Cookbook = Class.new

 Recipe = Class.new

 Class Cookbook
     def initialize(title)
         @title = title
     end
 end

Class Recipe
    def initialize(title, ingredients, steps)
        @title = title
        @ingredients = ingredients
        @steps = steps
    end
end

1 个答案:

答案 0 :(得分:1)

Class更改为class,即关键字class应以小写字母书写。

class Cookbook
    def initialize(title)
        @title = title
    end
end

class Recipe
    def initialize(title, ingredients, steps)
        @title = title
        @ingredients = ingredients
        @steps = steps
    end
end