我正在使用这个gem来帮助我制作固定的文件格式化程序。我正在按照文档操作,但得到一个错误
require('fixy')
class Record < Fixy::Record
include Fixy::Formatter::Alphanumeric
# Define record length
set_record_length 20
# Fields Declaration:
# -----------------------------------------------------------
# name size Range Format
# ------------------------------------------------------------
field :first_name, 10, '1-10' , :alphanumeric
field :last_name , 10, '11-20', :alphanumeric
# Any required data for the record can be
# provided through the initializer
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
# 2) Using a method definition.
# This is most interesting when complex logic is involved.
def last_name
@last_name
end
end
shinken = Reky.new('Sarah', 'Smith')
p shinken.generate最后一个方法: shinken.generate给出错误:generate': undefined methodfirst_name‘for # (NoMethodError)
这可能是什么原因造成的?
发布于 2017-10-19 03:11:51
试试这个:
def initialize(fn, ln)
@first_name = fn
@last_name = ln
end您的方法参数的名称可能与实例变量冲突?
https://stackoverflow.com/questions/46817410
复制相似问题