This is a simple hash extension which imitates behaviour of ruby's 2.1 keyword arguments. Check out examples below and spec file for sample usage.
def foobar(args = {})
[43] square » Rails.application.routes.draw do | |
» get "/foo" => "foo#bar" | |
» end | |
=> nil | |
[44] square » Rails.application.routes.routes | |
=> [ | |
[0] GET /foo(.:format) {:controller=>"foo", :action=>"bar"} | |
] | |
from /Users/lukaszstrzalkowski/Development/rails/actionpack/lib/action_dispatch/routing/route_set.rb:532:in `recognize_path' | |
[46] square » Rails.application.routes.recognize_path("/foo", :method => :get) |
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb | |
index a8368b6..abe4d71 100644 | |
--- a/actionpack/lib/action_dispatch/routing/route_set.rb | |
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb | |
@@ -500,11 +500,11 @@ module ActionDispatch | |
end | |
def recognize_path(path, environment = {}) | |
- method = (environment[:method] || "GET").to_s.upcase | |
+ environment[:method] = (environment[:method] || "GET").to_s.upcase |
class Post < ActiveRecord::Base | |
has_many :comments | |
end | |
class Comments | |
belongs_to :post | |
end | |
Post.first.comments.class # => Array | |
Kernel.instance_method(:class).bind(Post.first.comments).call # => ActiveRecord::Associations::CollectionProxy |
irb(main):001:0> s = 92.chr | |
=> "\\" | |
irb(main):002:0> s.size | |
=> 1 | |
irb(main):003:0> puts s | |
\ | |
=> nil | |
irb(main):004:0> s2 = s + s | |
=> "\\\\" | |
irb(main):005:0> s2.size |
Hello Bundler doc reader! |
perl -nle 'BEGIN { $l = 0; $SIG{ALRM} = sub { print $l; $l = 0; alarm(1) }; alarm(1) }; $l += 1' |
class Container | |
SETTER_METHOD_REGEX = /^(?<name>\w+)=$/.freeze | |
def initialize(params = {}) | |
@registry = {} | |
@registry.merge(params.symbolize_keys) if params.present? | |
end | |
def method_missing(method_name, *args, &block) | |
matched = method_name.to_s.match(SETTER_METHOD_REGEX) |
#/bin/bash | |
ICONV_CHARSET="$(enca -i -L polish $1)" | |
iconv -f $ICONV_CHARSET -t utf-8 < $1 > $2 |