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
# called in main | |
pry(main)> local_variables | |
=> [:__, :_, :_dir_, :_file_, :_ex_, :_pry_, :_out_, :_in_, :_erbout] | |
# called in method with no local vars | |
pry(main)> def a; local_variables; end | |
=> nil | |
pry(main)> a | |
=> [] |
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
.sign_up_in_content | |
= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) | |
= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| | |
%span | |
= f.input :email, :input_html => {:placeholder => 'Email'} | |
%span |
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
scope by_date, order("date desc") | |
scope stuff, -> (kind) {where("stuff = ?", kind) | |
scope pens, stuff("pen") | |
scope allans, stuff("allan").by_date |
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 User < ActiveRecord::Base | |
scope :hello, Proc.new { |param| param.blank? ? where("") : where("param = ?", param) } | |
end | |
User.hello(current_user_or_other_security_thig_or_somethng) | |
User.hello( "" ) | |
User.hello |
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 User < ActiveRecord::Base | |
scope :hello_lamb, ->(param) { param.blank? ? where("") : where("param = ?", param) } | |
scope :hello_proc, Proc.new { |param| param.blank? ? where("") : where("param = ?", param) } | |
end | |
User.hello_proc | |
# User Load (0.5ms) SELECT * FROM users |
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 User < ActiveRecord::Base | |
scope :hello_lamb, ->(param) { param.blank? ? where("") : where("param = ?", param) } | |
scope :hello_proc, Proc.new { |param| param.blank? ? where("") : where("param = ?", param) } | |
end | |
User.hello_lamb "a" | |
# User Load (0.5ms) SELECT * FROM users WHERE (param = 'a') | |
#=> #<ActiveRecord::Relation:0x3fe6eedeb984> |
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 Thing | |
def self.log str | |
p str | |
end | |
def test_log | |
begin | |
self.log "does not work" | |
rescue Exception => e | |
p e | |
end |
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 Mod | |
module ClassMethods | |
#put class methods here | |
end | |
module InstanceMethods | |
#put instnace methods here | |
end | |
def self.included(receiver) |
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 Log | |
def Log.included cls | |
cls.extend Log #also works by passing self, but Log is less confusing | |
end | |
def log str | |
p str | |
end | |
end | |
class Thing |
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
st_hash(const void *ptr, size_t len, st_index_t h) | |
{ | |
const char *data = ptr; | |
st_index_t t = 0; | |
h += 0xdeadbeef; | |
#define data_at(n) (st_index_t)((unsigned char)data[(n)]) | |
#define UNALIGNED_ADD_4 UNALIGNED_ADD(2); UNALIGNED_ADD(1); UNALIGNED_ADD(0) | |
#if SIZEOF_ST_INDEX_T > 4 |
NewerOlder