REE
4.51s - firebug Completed 200 OK in 1677ms (Views: 749.7ms | ActiveRecord: 134.0ms)
| # Drop this file in config/initializers to run your Rails project on Ruby 1.9. | |
| # This is three separate monkey patches -- see comments in code below for the source of each. | |
| # None of them are original to me, I just put them in one file for easily dropping into my Rails projects. | |
| # Also see original sources for pros and cons of each patch. Most notably, the MySQL patch just assumes | |
| # that everything in your database is stored as UTF-8. This was true for me, and there's a good chance it's | |
| # true for you too, in which case this is a quick, practical solution to get you up and running on Ruby 1.9. | |
| # | |
| # Andre Lewis 1/2010 | |
| # encoding: utf-8 |
| yes_no_conditions_creator = lambda {|yes_or_no,field_name| | |
| if yes_or_no == 'yes' | |
| {:conditions => "books.#{field_name.to_s} = true"} | |
| elsif yes_or_no == 'no' | |
| {:conditions => "books.#{field_name.to_s} = false or books.#{field_name.to_s} is null"} | |
| else | |
| {} | |
| end | |
| } | |
| # server at 8081 | |
| require 'rubygems' | |
| require 'faye/websocket' | |
| app = lambda do |env| | |
| ws = Faye::WebSocket.new(env) | |
| ws.onmessage = lambda do |event| | |
| puts event.data | |
| if event.data == 'started' |
| # БЫЛО | |
| # нужно создать такие коллбеки, которые могут быть скипнуты, если переменная skip_<имя_коллбека> возвращает true | |
| class A | |
| attr_accessor :skip_send_faye_notify | |
| after_create :send_faye_notify | |
| def send_faye_notify | |
| unless @skip_senf_faye_notify | |
| send |
| # Concern | |
| module SkipSpecificCallback | |
| extend ActiveSupport::Concern | |
| module ClassMethods | |
| def with_skip(callback_name, *args) | |
| options = args.extract_options! | |
| raise Exception, ":on not specified" if options[:on].blank? | |
| attribute_name = "skip_#{callback_name}" |
| class A | |
| state_machine do | |
| state :active | |
| state :removed | |
| event :remove do | |
| transition :active => :removed | |
| end |
| class Renderer | |
| def render | |
| puts "RENDERED" | |
| end | |
| end | |
| # а теперь создадим прокси :)) |
| class Image | |
| def after_save | |
| puts "after save image!" | |
| end | |
| end | |
| img = Image.new | |
| img.after_save # => "after save image!" |
| kiriy := Object clone | |
| kiriy name := "Kiriy" | |
| kiriy kill := method( | |
| ("my name is " .. call target name) println | |
| ("and i was killed by " .. call sender name) println | |
| ) | |
| killer := Object clone | |
| killer name := "Dron" |