相关疑难解决方法(0)

问题在ruby中支持双向语法

我有一种情况需要调用这样的东西:

class Office

  attr_accessor :workers, :id

  def initialize
    @workers = []
  end

  def workers worker
    type = worker.type
    resp = Worker.post("/office/#{@id}/workers.json", :worker => {:type => type})
    worker = Worker.new()
    resp.to_hash.each_pair do |k,v|
      worker.send("#{k}=",v) if worker.respond_to?(k)
    end
    self.workers << worker
  end

end
Run Code Online (Sandbox Code Playgroud)

工人阶级

class Worker
  attr_accessor :office_id, :type, :id

  def initialize(options={})
    @office_id = options[:office].nil? ? nil : options[:office].id
    @type = options[:type].nil? ? nil : options[:type].camelize
    if !@office_id.nil?
       resp = self.class.post("/office/#{@office_id}/workers.json", :worker => {:type => @type})
       @id = resp.id
       office = options[:office] …
Run Code Online (Sandbox Code Playgroud)

ruby rubygems ruby-on-rails

9
推荐指数
1
解决办法
121
查看次数

标签 统计

ruby ×1

ruby-on-rails ×1

rubygems ×1