Skip to content

Instantly share code, notes, and snippets.

View pawandubey's full-sized avatar

Pawan Dubey pawandubey

View GitHub Profile
# Run this file with ruby --enable-frozen-string-literal test.rb
# and then without the frozen string literal option and see the difference
class Foo
def initialize(v)
@v = v
end
attr_accessor :v
require 'benchmark/ips'
def tell_ape_with_block(&block)
tell_ape_block(&block)
end
def tell_ape_block(&block)
block.call
end
@pawandubey
pawandubey / permit_params.rb
Created April 24, 2017 16:50
Mass permit nested parameters from the Rails params object
# Gets around the difficulty of passing params with
# nested hashes as as of Rails 5.0, ActionController::Parameters
# no longer inherits from Hash.
#
# By default checks the params hash for the attributes contained in attrs
# and returns a hash containing the same values
def permit_params(params, attrs)
whitelisted_params = HashWithIndifferentAccess.new
attrs.each do |attr|
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- This one here!-->
<meta name="description" content="">
<meta name="fragment" content="!">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<base href="/index.html">