This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def test(callable) | |
| callable.call | |
| puts "here" | |
| end | |
| test(lambda{return}) #=> "here" | |
| test(proc{return}) #=> LocalJumpError |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Order < ActiveRecord::Base | |
| named_scope :order_counts, lambda { |*args| {:joins => :customer,:select => 'COUNT(DISTINCT customer_id) customer_id,category_id,product_price,quantity, SUM(product_price * quantity) AS my_sum', :group => 'category_id', :conditions => ['orders.created_at <= ? AND customers.temp = ?',args[0], args[1]]}} | |
| end | |
| Order.order_counts.first.my_sum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <h3><%= link_to (!(administrator.first_name.blank? && administrator.last_name.blank?) ? administrator.first_name + ' ' + administrator.last_name : administrator.email), admin_user_path(administrator) %></h3> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Objective < ActiveRecord::Base | |
| before_save :check_state | |
| ImmutableAttributesByState = { :open => [], :agreed => [:attrib1, :attrib2, :attrib3] } | |
| def check_state | |
| !ImmutableAttribuesByState[state].any? {|attribute| self.send(:"#{attribute}_changed?") } | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class String | |
| def reverse_with_print | |
| rev = reverse_without_print | |
| print rev | |
| return rev | |
| end | |
| alias :reverse_without_print :reverse | |
| alias :reverse_with_print :reverse | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Enumerable | |
| def inject_with_index(primer = nil) | |
| each_with_index.inject(primer) do |acc, arr_with_idx| | |
| yield acc, arr_with_idx[0], arr_with_idx[1] | |
| end | |
| end | |
| end | |
| [:a, :b, :c].inject_with_index({}) {|hsh, sym, idx| hsh.tap {|h| h[sym] = idx}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class List | |
| attr_accessor :per_page, :distribution, :page_count, :item_count | |
| def initialize(per_page=nil) | |
| @per_page = per_page || 21 | |
| @page_count = -1 | |
| @item_count = -1 | |
| @distribution = [] | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyClass | |
| def self.draw_some_routes(mapper) | |
| mapper.resources :accounts, :controller => 'authr/accounts', :only => [:new, :create] | |
| end | |
| end | |
| Rails.application.routes.draw do |map| | |
| MyClass.draw_some_routes(self) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Admin < Person | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Autotest.add_discovery { "rails" } | |
| Autotest.add_discovery { "rspec2" } |