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
| require "minitest/autorun" | |
| class Foo | |
| @option = "default" | |
| def self.build(value) | |
| klass = Class.new self | |
| klass.instance_variable_set :@option, value | |
| klass | |
| 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
| require "minitest/autorun" | |
| module Foo | |
| attr :add, :sub, :mul, :div | |
| def initialize(*) | |
| @add = -> (a, b) { a + b }.curry | |
| @sub = -> (a, b) { a - b }.curry | |
| @mul = -> (a, b) { a * b }.curry | |
| @div = -> (a, b) { a / b }.curry |
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
| require "open-uri" | |
| options = { | |
| content_length_proc: ->(length) { | |
| if length && 0 < length | |
| puts "content_length = #{length}" | |
| end | |
| }, | |
| progress_proc: ->(size) { | |
| puts "progress = #{size}" |
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 Post < ActiveRecord::Base | |
| validates_presence_of :title_en, :title_es | |
| def localized_attribute_for(name, locale = I18n.locale) | |
| "#{name}_#{locale}" | |
| end | |
| private | |
| def method_missing(name, *args) |
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 Post < ActiveRecord::Base | |
| validates_presence_of :locale | |
| validates_inclusion_of :locale, in: %w(en es) | |
| def self.with_locale(locale) | |
| where locale: locale | |
| end | |
| end | |
| class ApplicationController < ActionController::Base |
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
| array = [ | |
| { x: 1, y: 2 }, | |
| { x: 2, y: 2 }, | |
| { x: 3, y: 2 } | |
| ] | |
| array.sort_by do |k, v| | |
| [k, v] # => [{:x=>1, :y=>2}, nil], [{:x=>2, :y=>2}, nil], [{:x=>3, :y=>2}, nil] | |
| 0 | |
| 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
| # This class provides most of the features you'd get from i18n-active_record, | |
| # only simpler and lighter. | |
| class Translation < ActiveRecord::Base | |
| class Backend < I18n::Backend::KeyValue | |
| module Implementation | |
| attr_reader :store | |
| def initialize(subtress = true) | |
| @store = Store.new | |
| super store, subtress |
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
| require "helper" | |
| class CandidatesTest < MiniTest::Unit::TestCase | |
| include FriendlyId::Test | |
| class City < ActiveRecord::Base | |
| extend FriendlyId | |
| friendly_id :slug_candidates, use: :slugged | |
| 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 ActiveModel | |
| class RootSetting | |
| attr_reader :klass, :value | |
| def initialize(klass, value) | |
| @klass = klass | |
| @value = value | |
| end | |
| def root |