Imagine this case:
class Account < ActiveRecord::Base
def transfer(other, quantity)
tries = 0
begin
tries += 1
transaction do
self.quantity -= quantity| class Presenter < BasicObject | |
| def initialize(object) | |
| @object = object | |
| end | |
| def method_missing(method, *args, &block) | |
| @object.send method, *args, &block | |
| end | |
| module RailsHelpers |
| require "thread" | |
| class Account | |
| attr_reader :amount | |
| def initialize(amount) | |
| @amount = amount | |
| end | |
| def debit(amount) |
| # Of course we can make something like this | |
| class Module | |
| @include: (mixin) -> | |
| this.prototype[name] = method for name, method of mixin | |
| Saveable = | |
| save: -> alert "#{@name} saved!" | |
| class User extends Module |
Imagine this case:
class Account < ActiveRecord::Base
def transfer(other, quantity)
tries = 0
begin
tries += 1
transaction do
self.quantity -= quantity| # Passos para rodar: | |
| # 1. ruby extconf.rb | |
| # 2. make | |
| # 3. ruby benchmark.rb | |
| require 'benchmark' | |
| require 'bigdecimal' | |
| require './test' | |
| n = 50 |
| $(document).ready(function() { | |
| Highcharts.setOptions({ | |
| colors: ["#259E01", "#058DC7", "#7F8DA9", "#ADD981", "#DAF0FD", "#CD0D74"], | |
| chart: { | |
| borderWidth: 0, | |
| marginTop: 50, | |
| plotBackgroundColor: 'rgba(255, 255, 255, .9)', | |
| plotShadow: false, | |
| plotBorderWidth: 0, | |
| marginLeft: 50, |
| namespace :deploy do | |
| namespace :assets do | |
| task :precompile, :roles => :web, :except => { :no_release => true } do | |
| if capture("cd #{latest_release} && #{source.local.log(source.next_revision(current_revision))} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0 | |
| run "cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile" | |
| else | |
| logger.info "No changes on assets. Skipping pre-compilation." | |
| end | |
| end | |
| end |
| task :synchronize_site_names => :environment do | |
| require "csv" | |
| first_line_skipped = false | |
| CSV.foreach("doc/sgpd_svp.csv") do |line| | |
| first_line_skipped = true and next unless first_line_skipped | |
| svp_site_id, svp_site_name, oas_site_name = line |
| class TwitterBootstrapFormBuilder < ActionView::Helpers::FormBuilder | |
| delegate :capture, :content_tag, :tag, :to => :@template | |
| %w[text_field text_area password_field collection_select].each do |method_name| | |
| define_method(method_name) do |name, *args| | |
| errors = object.errors[name].any? ? " error" : "" | |
| error_msg = object.errors[name].any? ? content_tag(:span, object.errors[name].join(","), :class => "help-inline") : "" | |
| content_tag :div, :class => "clearfix#{errors}" do | |
| field_label(name, *args) + content_tag(:div, :class => "input#{errors}") do |
| page.driver.browser.switch_to.alert.accept | |
| page.driver.browser.switch_to.alert.dismiss | |
| page.driver.browser.switch_to.alert.text | |
| http://code.google.com/p/selenium/wiki/RubyBindings#JavaScript_dialogs |