ruby on rails - Confused with object initialization/instance variables -
i use following class definition
class workflow # class << self; attr_acessor :id, :name, :url end # please ignore troubleshooting attemp above didn't help, got objectnil def self.initialize ( id, name, url ) @id = id @name = name @url = url end # @return [object] def self.list ret = array.new wf = hash.new vco = vco.new vco.getall.each |link| link['attributes'].each |attr| wf[ attr['name'] ] = attr[ 'value' ] end ret.push( self.new( wf[ 'id' ], wf[ 'name' ], wf[ 'itemhref' ] ) ) end return ret end used as:
<% @workflows.each |wf| %> <tr> <td><%= wf.id %></td> <td><%= wf.name %></td> <td><%= wf.url %></td> </tr> <% end %> thus method workflow.list should return array of workflows. however, doesn't expected. when use
ret.push( self.new( wf[ 'id' ], wf[ 'name' ], wf[ 'itemhref' ] ) ) i'm getting "wrong number of arguments(3 0)" error. when use instead
ret.push( self.initialize( wf[ 'id' ], wf[ 'name' ], wf[ 'itemhref' ] ) ) the method list returns list of url strings (it last assignment in method, , should that) doing wrong?
to remove error on self.new call, change def self.initialize ( id, name, url ) def initialize ( id, name, url ). self.new tries create workflow instance,by calling default initialize method, don't take arguments,but providing arguments,which in turn throws error.
Comments
Post a Comment