Skip to content

Instantly share code, notes, and snippets.

use Merb::String => String
include Merb::String => String
extend Merb::String => String
class String
use Merb::String
end
C:\Users\jdeville\projects\rubyspec_o\rubyspec\core\argf
[90] » git diff --color
ESC[1mdiff --git a/core/argf/fixtures/bin_file.txt b/core/argf/fixtures/bin_file.txtESC[m
ESC[1mindex 2545e90..dec2cbe 100644ESC[m
ESC[1m--- a/core/argf/fixtures/bin_file.txtESC[m
ESC[1m+++ b/core/argf/fixtures/bin_file.txtESC[m
ESC[36m@@ -1,2 +1,2 @@ESC[m
ESC[31m-testESC[m
ESC[31m-testESC[m
ESC[32m+ESC[mESC[32mtestESC[m
# it "has the following type signature" do
# TypeSignature.new(@widget, :foo).
# returns_nil.and.
# has_argument(String, "Hello").and.
# has_argument(Fixnum, 123).and
# accepts_block
# end
# I like the following better. Description can be modified,
# I just like the describe to explain the spec
require File.dirname(__FILE__) + '/../../spec_helper'
describe "ObjectSpace.each_object" do
it "calls the block once for each living, nonimmediate object in the Ruby process" do
class ObjectSpaceSpecEachObject; end
new_obj = ObjectSpaceSpecEachObject.new
count = ObjectSpace.each_object(ObjectSpaceSpecEachObject) {}
count.should == 1
# this is needed to prevent the new_obj from being GC'd too early
TARGET: cs_class, cs_subclass, rb_subclass, struct
GENERIC_CLASS: true, false
GENERIC_METHOD: true, false
NUMBER_OF_PARAMETERS: 0,1,2,3,4,5,6,7,8
STATIC: true, false
REF_OUT_PARAMS: none, out, ref, params
AOPTIONAL: true, false
ADEFAULT: true, false
AOUT: true, false
NULLABLE_PARAM: true, false
def search(arr, t)
min = 0
max = arr.count -1
mid = (max-min)/2
if arr.count == 0 || (arr.count == 1 && arr[0] != t)
return -1
elsif t <= arr[mid]
return search(arr[0..mid], t)
else
return mid + search(arr[mid..-1], t)
@jredville
jredville / opt1.rb
Created August 12, 2011 19:24
Validation options
#this option is more explicit, but not as DRY and flexible
module BaseValidator
def validate_each(rec, attr, val)
#calls one or two known methods
end
end
class AsFooValidator < ActiveModel::EachValidator
include BaseValidator
def foo #one of the known methods
@jredville
jredville / Code.rb
Created November 8, 2011 20:31
Sample Code
# Batch Request Sample 1
def foo
end
#Batch Request Sample 2
def bar
end
$(function () {
$('.store-page-contents .store-order-action-coupon').insertBefore('.store-order-price-subtotal');
var header = $ ('<div>', {'class': 'intego-header-row'});
var head = '<h4>';
$(head, {
'class': 'intego-header-row-product',
'text': 'Product'
}).appendTo(header);
@jredville
jredville / ErcGrowl.el
Created January 6, 2012 05:53
ErcGrowl
(defvar growlnotify-command (executable-find "growlnotify") "The path to growlnotify")
(defun growl (title message)
"Shows a message through the growl notification system using
`growlnotify-command` as the program."
(flet ((encfn (s) (encode-coding-string s (keyboard-coding-system))) )
(let* ((process (start-process "growlnotify" nil
growlnotify-command
(encfn title)
"-a" "Emacs"