...either some Ruby code or your Rails app, use the differ gem. puts Differ.diff "foo", "boo" # => {"boo" >> "foo"} Usage There are several variants available, all using the base method diff...
Standard formatting is :ascii. You also have :html and :color formatting: diff = Differ.diff "foo", "boo" puts diff.format_as :html # => boo foo puts diff.format_as :color # => \e[31mboo\e[0m...
context 'with lots of required arguments' do it 'should work' do subject.something(:foo => 'foo', :bar => 'bar', :baz => 'baz').should == 'Hello world' end it 'should work again' do subject.stub...
...target => 'universe' subject.something(:foo => 'foo', :bar => 'bar', :baz => 'baz').should == 'Hello universe' end it 'should work yet again' do subject.stub :target => 'multiverse' subject.something(:foo => 'foo', :bar => 'bar', :baz => 'baz').should...
...passes with [up-hungry] fragments. Targeting sibling elements now supports union selectors like .parent .foo, .parent .bar...
...getter/setter functions, and probably never will. However, you can define getters/setters using Object.defineProperty: object = {} fooValue = undefined Object.defineProperty object, 'foo', get: -> fooValue set: (newValue) -> fooValue = newValue Some people are also doing...
...would actually be longer than two lines: Dies ist ein Text mit mehreren Zeilen foo bar would be rendered as Dies ist ein Text mit mehreren Zeilen... I recommend building...
Copy the attached file to config/initializers/indent_string.rb and you can say "foo".indent(4) # " foo" Note you will find many simpler implementations of this method on the Interweb. They probably won...
it 'should indent the string by the given number of spaces' do "foo".indent(2).should == " foo" end it 'should indent multiple lines line by line' do
URLs can transport key/value pairs ("parameters") using this syntax: /path?foo=bar If the value is blank, mind these subtle differences: URL Meaning /path?foo= Parameters have a key foo...
...Its value is an empty string. /path?foo Parameters have a key foo. Its value is null. /path Parameters have no key foo...
status, headers, body = @app.call(env) session = env['rack.session'] Rails.logger.info("Value of session['foo'] is: " + session['foo'].inspect) [status, headers, body] end end You may not be able to...
...and you modify the copy, you will run into the following behavior: original_hash = { foo: { bar: 'original value' } } copied_hash = original_hash.dup copied_hash[:foo][:bar] = 'changed value' original_hash # => { foo...
...changed value" } This is, because { bar: 'baz' } is an object, which is referenced in :foo. The copy of original_hash still holds the reference to the same object, so altering...
...to look something up and gets different results on different Rubies. Consider this: module Foo FOO = 42 end class Bar include Foo end On Ruby 1.8, Bar won't have...
...FOO defined as a constant since that's (even though it's accessible): 1.8.7 > Foo.const_defined? :FOO => true 1.8.7 > Bar.const_defined? :FOO => false 1.8.7 > Bar::FOO => 42 Ruby 1.9 introduces...
...Rails versions for each of the bundles: ~/my_project$ bundle show rails .../gems/rails-3.0.20 ~/my_project$ cd foo && bundle show rails .../gems/rails-3.2.13 Now you will usually just use bundle exec to run stuff...
~/my_project$ bundle exec ruby -e "require %(rails) ; puts Rails.version" 3.0.20 ~/my_project$ cd foo && bundle exec ruby -e "require %(rails) ; puts Rails.version" 3.2.13 So far, so good.
During debugging you might pepper your code with lines like these: console.log('foo = ' + foo + ', bar = ' + bar) I recommend to use variable interpolation instead: console.log('foo = %o, bar = %o', foo, bar...
...look at its contents Another concise way to write the statement is this: console.log({ foo, bar }); This uses Javascript's new destructuring syntax and is actually shorthand for: console.log({ foo...
include_hash Matches if the given hash is included in the receiving hash: { :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'a') # passes { :foo => 'a', :bar => 'b' }.should include...
...hash(:foo => 'b') # fails { :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'a', :baz => 'c') # fails
...to be able to say this? When I go to the user form for "foo@bar.de" # goes to edit_user_path(User.find_by_anything!('foo@bar.de')) When I go to the form...
...for the user "foo@bar.de" # goes to edit_user_path(User.find_by_anything!('foo@bar.de')) When I go to the form for the user above" # goes to edit_user_path(User.last)
...x you might instead want to use an older cheat sheet. Expectations # RSpec expect(foo).to.eq("value") expect(foo).to_not eq("value") # Jasmine expect(foo).toBe("value")
...not.toBe("value") Mocks # RSpec expect(foo).to_receive(:method).twice.with('arg').and_return('value') # Jasmine spyOn(foo, 'method').and.returnValue('value') expect(foo.calls.count()).toBe(2) expect(foo.method).toHaveBeenCalledWith('arg...
...Here is a useless comment. -# It will be removed. class File1 - def foo + def bar # ... end end diff --git a/file2.rb b/file2.rb index 550e1c6..600f4e3 100644 --- a/file2.rb +++ b/file2.rb...
...Here is another useless comment. class File2 - def foo + def bar # ... end end While you can easily stage such changes using git add -p, you can be much faster when...
...computed property name in square brackets. We may now use Account instances with up.util.isBlank(): foo = new Account('foo@foo.com') bar = new Account('') console.log(up.util.isBlank(foo)) // prints false console.log(up.util.isBlank(bar)) // prints...
...to be more precise, it inherits from Hash): errors = ActiveModel::Errors.new(Object.new) => {} >> ?> errors.add(:base, "foo") => ["foo"] >> errors.add(:base, "bar") => ["foo", "bar"] >> ?> errors => {:base=>["foo", "bar"]} If you need to hack...
...the errors it will decompose arrays. For attributes with multiple errors such as :base => ["foo", "bar"] it yields once per value ("foo" and "bar" here) within the array and not...
Our preferred syntax prefixes the issue title with its ID in brackets, e.g. [FOO-123] Avatars for users. Here is how to generate that from an issue in Linear...
...be fixed with the :prefix-option: class Form state_machine :first_wizard_stage, prefix: :foo do state :completed end state_machine :second_wizard_stage, prefix: :bar do state :completed
This defines the following: constants: Form::STATE_FOO_COMPLETED and Form::STATE_BAR_COMPLETE instance methods: #foo_completed? and #bar_completed? Fix bug where additional inclusions of RailsStateMachine::Model...
uri = URI('http://example.com/?foo=1&bar=2') stub_request(:get, 'example.com').with(query: {foo: 1, bar: 2}) Net::HTTP.get(uri) # ===> Success If you only want to check if foo...
uri = URI('http://example.com/?foo=1&bar=2') stub_request(:get, 'example.com').with(query: hash_including(foo: 1)) Net::HTTP.get(uri) # ===> Error hash_including doesn't parse query values to string, you...
errors.add_to_base('failed') if bad_things? end end ^ # app/models/foo.rb require 'user' class Foo # something happens here end Now, when your environment is booted, Rails will automatically load your...
...models, like User. In our example, when Foo gets loaded, it will require the User class itself again. Since Ruby 1.8 identifies required files by the string you used (as...
We can call the method we're overriding inside our monkey patch: class Foo def bar(argument) 'Hello' + argument end end module FooExtensions def bar super(' in my') + ' World...
end class Foo prepend FooExtensions # the only change to above: prepend instead of include end Foo.new.bar # => 'Hello in my World' As mentioned, monkey patches are usually a threat to...
...try not to throw synchronous exceptions when encountering fatal errors. So avoid this: function foo(x) { if (!x) { throw "No x given" } else return new Promise(function(resolve, reject) { ... }); } }
...s hard to handle errors when calling foo, since we need to handle both a synchronous throw and an asynchronous rejection. Look how much code we need to handle failures...