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...

makandra dev

...when SomeException is raised Some advanced examples for scriptable breakpoints: debugger(pre: "info ;; puts @foo ;; info ;; bt ;; break @user.name") # starts debugging session after executing each of the pre commands

...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.

...method, created by a user in commit d47bf443: def hello 'world' end ^ $ git blame foo d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 1) def hello d47bf443 (Arne...

...is how Git blames those lines with and without the -w switch: $ git blame foo d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 1) def hello f5fae4c1 (Señor...

...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...

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...

...attribute on it, but then don't attach it to the DOM: $element = $(' '); $element.data('foo', 'bar'); After the last line in the code sample above, $element can no longer be...

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...

In Rubocop you might notice the cop Style/CaseEquality for e.g. this example: def foo(expected, actual) expected === actual end In case expected is a Regex, it suggests to change it...

...to the following pattern: def foo(expected, actual) expected.match?(actual) end In case expected is a Regex or a String, you need to keep ===. Otherwise the actual expression is always...

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...

makandra dev

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

...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...

apidock.com

...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...

...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...

\di Create user that can create databases CREATE USER harry IDENTIFIED BY 'foo'; CREATE ROLE username WITH createdb LOGIN [PASSWORD 'password']; Change password of an existing user ...

makandra dev

...branch means switching branches. Example git checkout HEAD~2 app/models/foo.rb … drops all modifications of foo.rb and replaces the file with its version from HEAD~2 = two commits before the current...

...set the path=/ option. Reading cookies A result may look like this: hello=universe; foo=bar This means that there are 2 cookies: "hello" with value "universe", and "foo" with...

...cookie that we just stored, and any cookies that existed previously. document.cookie // => "hello=universe; foo=bar; yes=please" That applies to all browsers. Options Cookie options like expiry or the...

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...

...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...

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...