"extended by #{obj}" end end class MyClass include MyModule # => "included by MyClass" end MyClass.new.extend(MyModule) # => "extended by #<MyClass:0x007fd included, extended
value| if respond_to?("#{key}=") send("#{key}=", value) else instance_variable_set("@#{key}", value) end end end define_method(:price=) do |price_str| instance_variable_set( '@price', price_str.delete(',').to_i ) end end p Book.new(author: 'moro', price: '1,980')
= #{name.to_s.classify} klass.where(#{fk}: id) end def #{name}=(value) values.each do |value| #{name.to_s.classify}.create!(...) end end RUBY end ͦ͠͏ͳ࣮Πϝʔδ
url end def submit req = Net::HTTP::Post.new(@url.path) req.set_form_data('content' => @content) Net::HTTP.start(@url.hostname, @url.port) do |h http.request(req) end end end
block end def submit(record) content = @content_builder.call(record) Censoring.new(content, @endpoint).submit end end # ---------------- post_adapter = CensorAdapter.new(endpoint) do |post| [post.title, post.body].join("\n\n") end post_adapter.submit(post)
src='http://img.example.com/#{photo.id}' />" end after_save :submit_content_monitoring private def submit_content_monitoring @@censor_adapter.submit(self) end end