...RANDOM on bash returns a random integer between 0 and 32767. echo $RANDOM 9816 echo $RANDOM 30922 If you want to limit that to a certain maximum, you can just...
...activation of that feature on the value of that constant: private def captcha_valid? return true if SKIP_CAPTCHA ... To manually activate the feature in tests that actually need it...
...type of an attribute, you can just use ActiveRecord's columns_hash method. It returns a hash of column objects that include a type attribute (and more database-related information...
...lets you easily traverse nested hashes, arrays, or even a mix of them. It returns nil if any intermediate value is missing. x = { foo: { bar: [ 'a', { baz: 'x' } ] } }
Did you return false in a before_validation callback...
...a result is obtained. Also see our card Ruby: A small summary of what return, break and next means for blocks...
...pair as a hash map, where you lookup keys in the first column and return values from the second...
...development you may need to mock HTTP responses. This is a simple service to return various HTTP responses...
So you have a method returning a regular expression but one case that should not yield a matching Regexp object but still keep the API stable? Just return one that...
...Ruby. It automatically picks the best runtime available to evaluate your JavaScript program, then returns the result to you as a Ruby object...
var presence = null; function isPresent() { if (_.isNull(presence)) { presence = $('body').is('.touch_device'); } return presence; } return { isPresent: isPresent...
This returns the name (including path) of your current layout: response.layout => "layouts/admin" # inside views that are using the 'admin' layout You most likely do not need the full path, so...
...winner.promise() @all: (promises) -> # Pass an additional resolved deferred to $.when so $.when will # not return the given deferred if only one deferred is passed. $.when(@resolve(), promises...) @reject: (value) ->
...setting it as a simple attribute will do. Easy workaround Define a method that returns the constant and stub that method: class Earth TILT = 23.4 #degree def self.tilt TILT
^ Earth.should_receive(:tilt).and_return 10.5 # or Earth.stub :tilt => 10.5 Sometimes you can't add this method and must have that CONSTANT there. Master mode is for you.
...substring (no ^ and $ markers at the beginning and end), you are still expected to return a replacement for the whole string that was piped through the transform. If you don...
Best results in other decks
...following code demonstrates: class Ambiguous def x; 1; end # A method named "x". Always returns 1 def test puts x # No variable has been seen; refers to method above: prints...
...this line prints 2 end end That also means that you cannot assign the return value of x to a local variable named x: class Ambiguous def x; 1; end...
...following code demonstrates: class Ambiguous def x; 1; end # A method named "x". Always returns 1 def test puts x # No variable has been seen; refers to method above: prints...
...this line prints 2 end end That also means that you cannot assign the return value of x to a local variable named x: class Ambiguous def x; 1; end...