This file contains hidden or 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 SomeController | |
| def some_action | |
| @list_of_partials = [] << "say_hello" << "ask_about_their_day" << "say_goodbye" | |
| respond_to do |format| | |
| format.js { render :update_some_page_section } | |
| end | |
| end | |
| end |
This file contains hidden or 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 Foo | |
| def self.bar(instance = new) | |
| instance.send(:bar) | |
| end | |
| protected | |
| def bar | |
| "protected!" | |
| end | |
| end |
This file contains hidden or 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
| # From: | |
| # http://www.alphasights.com/apply/ruby-developer-london | |
| # The rules: | |
| # Ordering in the input is not defined. Ordering in the result is not important. | |
| # Do not rely on the names of the hash keys other than :time. | |
| # The field below executes your code in a Sandbox with $SAFE=4, | |
| # so you can't define new classes, use global variables, etc. | |
| def remove_duplicates(log) | |
| group_by_date(log).map do |time, entries| |
This file contains hidden or 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 Foo | |
| def initialize(options={}) | |
| @logger = options[:logger] || Proc.new { } | |
| end | |
| def do_stuff | |
| @logger.call "Logged!" | |
| end | |
| end |
This file contains hidden or 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
| public class PostCode { | |
| private static final String DIGIT_ALPHA_ALPHA = "\\d[A-Z][A-Z]"; | |
| private static final int OUTCODE_LENGTH = 3; | |
| private String inCode; | |
| private String outCode; | |
| public PostCode(String rawPostCode) { | |
| String postCode = removeSpacesAndUpperCase(rawPostCode); | |
| inCode = postCode.substring(0, inCodeLengthFrom(postCode)); | |
| outCode = postCode.substring(inCodeLengthFrom(postCode)); |
This file contains hidden or 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
| find test -iname "*_test.rb" | xargs grep -c "should" | sort -n -k2 -t: | grep -v "helper" |
This file contains hidden or 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
| #!/bin/bash | |
| test_files() { | |
| find test -iname "*_test.rb" | xargs grep -l "should" | grep -v "helper" | grep -v "performance" | grep -v "browser" | |
| } | |
| time_command() { | |
| local cmd=$* | |
| TIMEFORMAT="%3R" | |
| (time $cmd > /dev/null) 2>&1 | |
| } |
This file contains hidden or 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
| baz = true | |
| foo, bar, bat = if self.baz? | |
| puts "this gets executed" #=> But puts returns nil, which gets assigned to foo, bar and bat | |
| else | |
| puts "this doesn't get executed" | |
| end |
This file contains hidden or 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 Parent < ActiveRecord::Base | |
| has_many :children | |
| validates :name, presence: true | |
| end | |
| class Child < ActiveRecord::Base | |
| belongs_to :parent | |
| end | |
This file contains hidden or 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 Suppress | |
| def initialize method | |
| @method_name = method.to_sym | |
| end | |
| def self.method_named method | |
| new method | |
| end | |
| def on_object object, &block |