Enumerable#all? returns true for an empty collection. This totally makes sense but you have to think about it when making assumptions on relations which might be empty. [].all?(&:will...
...researcher.papers.all? { |topic| topic == 'computer_science' } researcher.destroy! end end There are more methods in Enumerable (returning boolean values) where you might need to think twice with empty collections...
...the DOM now, the will be gone, but its contents will be kept. $container.html() // returns " Hello World" Also note that contents() includes text and comment nodes which is essential for...
class DeepThought extend ActiveSupport::Memoizable def life_universe_and_everything # some lengthy calculation returning 42 end memoize :life_universe_and_everything end Then #life_universe_and_everything will of...
...parameter at all. To clarify: This not only disables the memoization, but will also return wrong results! The best solution is to use the Memoizer gem instead...
...s #collect is to call a method on each list element and collect the return values in a new array: ['hello', 'world', 'this', 'is', 'nice'].collect(&:length...
...method collect_ids on your ActiveRecord models, scopes, integer scalars and collections, which will return a list of their IDs: User.last.collect_ids # => [9] [User.first, User.last].collect_ids # => [1, 9] User.active.collect...
...attrs.fetch_values :name, :email Hash#to_proc Turns a Hash into a Proc that returns the corresponding value when called with a key. May be useful with enumerators like #map...
...sure to do it this way: params.to_hash.symbolize_keys.merge(:include => { :user => :avatar }) (Note that params.to_hash returns a hash with string keys...
...src attribute. To overcome this, use the trick below. Background The ngSrc directive explicitly returns when the attribute value is falsy. As a workaround, set a "blank" image src when...
class Foo include Memoizer memoize def bar ... end end This is because def returns the method name as a symbol in...
...point to another window last_handle = page.driver.browser.window_handles.last page.driver.browser.switch_to.window(last_handle) Mind these: find_window returns a window handle, which is something like "{485fa8bd-fa99-4c26-9edc-97fed060036f}". If you already...
...of some other major changes has_content? doesn't match hidden elements body now returns the unmodified source Node#wait_until and Session#wait_until have been removed. => Alternative: Node...
Some modern Javascript APIs return iterators instead of arrays. In plain Javascript you can loop through an iterator using for...of: var iterator = ...; for (var value of iterator) { console.log(value...
...var offset = $(hash).offset(); if (offset) { $('html, body').animate({ scrollTop: offset.top }, 'slow'); location.hash = hash; return false; } }); Note that this could basically work for any element whose offset() you can read...
...dove into another shell (e.g. with sudo su username) you will close it and return to the previous one. !! Repeat the previous command. Can be used inside other commands, e.g...
...moored Moored (anchored) mine. --drifting Drifting mine. In Ruby ^ Docopt::docopt(the_above_doc) # returns: {"ship"=>true, "new"=>false, " "=>["Guardian"], "move"=>true, " "=>"100", " "=>"150", "--speed"=>"15", "shoot"=>false, "mine"=>false...
...using plain Ruby: "foo=3Dbar".unpack('M')[0] # => "foo=bar" Note that unpack will return an array. Our result is the 1st item. Encode a string as Quoted Printable
$children = $container.children() if $children.length == 0 $container else $lastChild = $children.last() $lastContent = $container.contents().filter(-> # Only return nodes that are either elements or non-empty text nodes @nodeType == 1 || (@nodeType == 3 && _.strip...
...validate which uses Nokogiri to validate an XML document against an XSD schema. It returns an array of Nokogiri::XML::SyntaxError objects. require 'rubygems' gem 'nokogiri' require 'nokogiri'
...set-hue($color, $target-hue) $current-hue: hue($color) $degrees: $target-hue - $current-hue @return adjust-color($color, $hue: $degrees) It now works as expected: adjust-hue(#ffff00, 120)
...t care about any callbacks or validations. Note that create_without_callbacks does not return the object, so you might want to do record = Record.new.tap(&:create_without_callbacks)
...on that, just because CookieJar#to_hash is inherited from Hash and will just return self. Bummer. You need to do it yourself, for example by using collect_hash:
+-----+------+------+ | 30 | 20 | 10 | | 30 | NULL | NULL | +-----+------+------+ Solve this by using IFNULL: it returns the selected value if present and a given alternative if it would select NULL:
...create a new object. Because of this, comparing two jQuery collections with == will never return true, even when they are wrapping the same native DOM elements: $('body') == $('body') // false
...IMAP, send the following string (incl. "01"!): 01 LOGIN user@domani.io $password The server should return something like: * CAPABILITY IMAP4rev1 LITERAL+ SASL-IR ... 01 OK Logged in To log out, send...