...It just does memoization and does it well. The syntax is similiar also: class Foo include Memoizer def bar ... end memoize :bar end If you're using Ruby 2.1+, you...
...can write this even shorter: class Foo include Memoizer memoize def bar ... end end This is because def returns the method name as a symbol in...
...that contains values from Ruby variables. E.g. you want to call a Javascript function foo(...) with the argument stored in the Ruby variable @foo. You can do this by using...
...that are tagged with just awesome and cool User.tagged_with("awesome", "cool", :owned_by => foo ) # Users that are tagged with just awesome and cool by 'foo...
...a mix of them. It returns nil if any intermediate value is missing. x = { foo: { bar: [ 'a', { baz: 'x' } ] } } x.dig(:foo, :bar) # => [ 'a', { baz: 'x' } ] x.dig(:foo, :bar, 1, :baz...
x.dig(:foo, :wronk, 1, :baz) # => nil There is a tiny gem that backports this...
...for cleaning up multiple local database server installations in batches. Derivative database names like foo_development and foo_test4 for foo are handled together with foo to allow for per...
...probably did something like this in your state_machine...
def self.final_states [ :foo, :bar ] end transition (all - machine.final_states - [:baz]) => :target_state Instead, define the source states like...
def self.final_states [ :foo, :bar ] end transition (all - (machine.final_states | [:baz])) => :target_state
...s SimpleDelegator (or vice versa). This following will not work: class MyDecorator < SimpleDelegator def foo end end MyDecorator.new(Object.new).andand.foo The reasons are a bit subtle, basically SimpleDelegator will "force...
...When you set a key, you can read its value just like always. hash['foo'] = 23 hash['foo'] // => 23 But instead of returning undefined for unset keys, our get proxy...
...set the xsi:type attribute like this: client.call(:rpc_method, message: { :some_object => { :name => 'foo', :other => 'bar', '@xsi:type' => 'somenamespace:SomeObject' } } ) This is roughly equivalent to this in Javaland, where...
...you have magic generated stub code: SomeObject so = new SomeObject(); so.setName('foo'); so.setOther('bar'); client.rpcMethod(so...
The good E. g. in the following example, Array could mean either Foo::Array or simply Array: class Foo def list Array.new end end What Ruby does here...
...is to see if the name Array makes sense inside of Foo::, and if that fails, resolves it to ::Array (without a namespace). The bad This is relevant for old...
...would be to test if the current page has a button with the label "Foo". There are many ways to render a button with CSS: Foo We cannot express it...
...with a single have_css() matcher, since we need the { text: 'Foo' } option for some cases ( ), but not for others ( ). What we can do is chain multiple have_css() matchers...
...whenever we try to select an option from a Capybara complains: No such option 'Foo' in this select box. Available options: 'Foo', 'Bar', 'Baz' (Capybara::OptionNotFound) This seems to happen...
You can restore the original implementation of stubbed methods with unstub: object.stub(:foo => 'bar') # ... object.unstub(:foo) In recent RSpecs double is the preferred way to create a mock...
...the argv[0] value, which may show up in process listings. E.g. exec ['ls', 'foo'], 'foo.bar', 'baz.bar' options see the Ruby docs The shell used is /bin/sh on Unix-like...
...Calc's AutoCorrect will change the first character of the last line to uppercase: foo => foo bar bar baz Baz To fix this, go to Tools / AutoCorrect Options, choose the...
...the @template field to the name of another action: class Mailer < ActionMailer::Base def foo subject "Hello World" end def bar subject "Hello Universe" @template = 'foo' end
...adding additional keys to the options hash: form.build_nested_records(:actors, :minimum: 4, name: 'Foo', active: true) If you want to call a different method rather than build, you can...
This will reduce the filesize of foo and bar to 0 bytes: truncate -s0 foo bar If the files do not exist they will be created. You can use this...
...it good for local testing. Usage examples with curl equivalent: # curl post curl --data "foo=23&bar=42" https://example.org/blub # httpie post http https://example.org/blub foo=23 bar...
...get install node-ws # wscat -c ws://echo.websocket.org connected (press CTRL+C to quit) > foo < foo > bar
...Up to three arguments are passed to git show. Example output: commit 048054b1df87576f7c59cc0161cc331c44d2ea6b Author: Foo Bar <foo@bar.com> Date: Fri Apr 5 14:24:24 2019 +0200 [#165086636] My Pivotal Tracker...
...Instead you should explicitly trigger those events via Javascript. Examples for Capybara: page.execute_script("$('#foo').focus()") page.execute_script("$('#foo').blur()") If this doesn't help, a workaround is to create...
...will give you the string that appears most often in an array: names = %w[ foo foo bar bar bar baz ] names.group_by(&:to_s).values.max_by(&:size).try(:first)
...a method with several keyword arguments and a double-splat argument (e.g. def m(foo: 'bar, option: 'will be lost', **further_options)) there is a dynamically created Symbol (e.g. 'culprit...