This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
fieldset { display: block; } | |
.alternative { display:none; } | |
.alternative-selected { } | |
</style> |
This file contains 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
# Include this module in a class to add enhanced attr_accessor | |
# functionality. With this module included, ... | |
# | |
# * You may provide a block to an attr_accessor call that accepts | |
# a base attribute name and returns a default value for each | |
# instance attribute. | |
# * Any attribute name consisting of a base name followed by a | |
# "?" suffix represents a boolean attribute. | |
# | |
# If the including class has its own #initialize method, that |
This file contains 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 name assignment == | |
# A Ruby module's name is determined when it first becomes | |
# assigned as the value of a top-level constant or of a | |
# constant in a module that has received a name. | |
# The module's name represents the hierarchy of containership, | |
# and is not dependent upon the execution path of the code | |
# that defined the module (as opposed to the module nesting | |
# for defined methods -- see below). | |
p [self, self.class, Module.nesting] # => [main, Object, []] |
This file contains 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
# Get ourselves a clean, top-level binding. | |
def main_binding | |
binding | |
end | |
module ModuleUtils | |
module ModuleMethods ; end | |
self.extend ModuleMethods | |
module ModuleMethods |
This file contains 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 is a mixin module that adds support for tail-recursive | |
# style programming in Ruby without relying on any true tail | |
# recursion optimization in the Ruby virtual machine. | |
# | |
# Since tail recursion calls are actually deferred until after | |
# returning from the method that invoked #tail, recursions can | |
# be "nested" to an unlimited depth without overflowing the | |
# stack. | |
# | |
# The including module can define tail-recursive methods within |
This file contains 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
# A module for inclusion in a class of objects that delegate to and | |
# provide restricted interface definitions for underlying "occurrence" | |
# objects. | |
# | |
# This is useful for purposes such as to enforce the same API for a | |
# unit under test as for mocks and stubs of the same unit used for | |
# testing other units. | |
# | |
# This is a proof of concept demonstration and is not well-tested, | |
# production-ready code. |
This file contains 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'bundler' | |
require 'beaneater' | |
beanstalk = Beaneater::Pool.new(['localhost:11300']) | |
sleep_tube = beanstalk.tubes['sleeper-take-a-nap'] | |
sleep_tube.put '-' |
This file contains 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
fib = Fiber.new do |val| | |
puts ' -- 2 --' | |
puts 'fiber started & got: ' + val | |
puts 'now yield with "1st yield"' | |
val = Fiber.yield('fiber yield 1') | |
puts ' -- 4 --' | |
puts '1st yield got: ' + val | |
puts 'now yield with "2nd yield"' |
This file contains 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
# ./config/initializers/deferred_uniqueness_validations.rb | |
# | |
# This initializer adds support for deferred processing of | |
# ActiveRecord uniqueness validations. When a uniqueness | |
# validation is deferred using the :deferred => true option, it is | |
# not checked before save. Instead, if there is a uniqueness | |
# constraint defined for the column in the database, and if the | |
# save operation raises an ActiveRecord::RecordNotUnique | |
# exception, then the validation is performed so that the precise | |
# cause can be determined and the appropriate error information |
This file contains 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 Trinary | |
class << self | |
def ~ ; ~new ; end | |
def -@ ; -new ; end | |
def +@ ; +new ; end | |
end | |
def initialize(digits=[]) | |
@digits = digits | |
end |
OlderNewer