...on your module's singleton class: module SomeTrait as_trait do define_singleton_method :foo do # ... end end end Using def (has caveats!) Alternatively, you can def the method on...

...cookies can simply set or expect by using one of the following options: helper.cookies[:foo] = "bar" helper.cookies.signed[:foo] = "bar" helper.cookies.encrypted[:foo] = "bar" Request Specs In request specs you can simply...

...placed in your .bashrc or any location that is loaded by it. # Usage: linearcommits FOO-123456 # Alternative usage: linearcommits https://linear.app/some-workspace/issue/FOO-123456 function linearcommits { if test "$1" then local LINEAR...

...a regular git show). Example output for linearcommits ABC-165086636 --stat: commit 048054b1df87576f7c59cc0161cc331c44d2ea6b Author: Foo Bar <foo@bar.com> Date: Fri Apr 5 14:24:24 2019 +0200 [ABC-165086636] Linear issue...

...You can use it to dispatch an event on a jQuery object: let $element = $('.foo') $element.trigger('change') A caveat is that such an event will be received by jQuery event...

...listeners, but not by native event listeners: let $element = $('.foo') $element.on('change', event => console.log('I will be called')) $element[0].addEventListener('change', event => console.log("I WON'T be called")) $element.trigger...

Given this class: class Foo class Bar end end If you want to clean up this code with the modularity gem, you might try something like this: class Foo

end end end Note that this changes Bar's full class name from Foo::Bar to BarTrait::Bar. If you have methods inside Foo (or other classes), you would...

stackoverflow.com

...the Method object Dead simple: Get the method object and ask for its owner: "foo".method(:upcase) # => # "foo".method(:upcase).owner # => String Look up a method's source location

class Example; def method() end; end # => nil Example.new.method(:method).source_location # => ["(irb)", 11] "foo".method(:upcase).source_location # => nil # String#upcase is a native method that's defined in...

...was removed from the DOM } attributeChangedCallback(attribute, oldValue, newValue) { // the given attribute was changed } foo() { // a custom method } } customElements.define('my-element', MyElement) Note that this class automatically describes the JavaScript...

...attribute. However, you can configure it to do so: fill_in 'Search contacts', with: 'foo' # => raises "Unable to find field 'Query'" Capybara.enable_aria_label = true # enable [aria-label] support for...

fill_in 'Search contacts', with: 'foo' # => fills in the query "foo" Also see An auto-mapper for ARIA labels and BEM classes in Cucumber selectors

tenderlovemaking.com

...attributes, which would not be possible with a private attribute. class B def <=>(other) foo <=> other.foo end protected attr_accessor :foo

...you out on creating it. Simply use Nokogiri's xpath_for: Nokogiri::CSS.xpath_for('#foo') # => ["//*[@id = 'foo']"] Nokogiri::CSS.xpath_for('#foo .bar:nth-of-type(2)') # => ["//*[@id = 'foo']//*[contains(concat...

Usage: /foo+/ Shorthand for creating a regular expression object RegExp() object Usage: RegExp("foo+") or new RegExp("foo+") No surrounding slashes required (they're the literal markers)

...index they matched. Multiple calls to test() will advance this pointer: matcher = new RegExp("foo", "g") // <- "global" flag matcher.test("foobar") // => true matcher.lastIndex // => 3 (where the regexp stopped scanning) matcher.test("foobar...

...JSON, and then escaping all code points above 127 using unicode escape sequences: escapeHighASCII('{"foo":"xäy"}') // => '{"foo":"x\\u00e4y"}' Escaping high ASCII in JavaScript function escapeHighASCII(string) { let unicodeEscape = (char...

...Use the new tag syntax Cucumber 1/2 Cucumber 3 @tag @tag ~@tag not @tag @foo, @bar (@foo or @bar) So you need to replace a hook like this: AfterStep('~@javascript...

masilotti.com

test "user can be created" do post users_path, params: { first_name: "Foo", last_name: "Bar" } assert User.count == 3 end Good example: test "user can be created" do...

...assert_difference "User.count", 1 do post users_path, params: { first_name: "Foo", last_name: "Bar" } end end Conclusion Benefits You tests will become more explicit by default (less tools such...

...method with the same name. Take this example: class Project < ActiveRecord::Base def user "foo" end belongs_to :user end Project.new.user still returns "foo". The reason for this is that...

...belongs_to does is actually this: class Project < ActiveRecord::Base include FeatureMethods def user "foo" end end module Project::FeatureMethods def user # association getter goes here end end

u.to_h => {:gid=>1, :email=>"hans@peter.de", :name=>"Hans Peter"} u.foo NoMethodError: undefined method `foo' for # compare objects: UserPreview.new(1, 'hans@peter.de', 'Hans Peter') == UserPreview.new(1, 'hans@peter.de', 'Hans Peter') => true

...image to one that is based on Alpine Linux. Debian image sorting: bar Bar foo Foo Alpine image sorting: Bar Foo bar foo Explanation Alpine Linux is a very slim...

...for :freeze support. As an example, consider the following Yaml file: --- message: - hello - universe foo: bar: baz: "example" We can now load it as usual, but pass freeze: true.

...YAML.safe_load_file('example.yml', freeze: true) => {"message"=>["hello", "universe"], "foo"=>{"bar"=>{"baz"=>"example"}}} The Hash itself is frozen: >> test.frozen? => true And no matter how deep you dig, everything inside that...

docs.ruby-lang.org

The sprintf method has a reference by name format option: sprintf("% d : % f", { :foo => 1, :bar => 2 }) # => 1 : 2.000000 sprintf("%{foo}f", { :foo => 1 }) # => "1f" The format identifier % stands for...

...parameters as described below. If possible, specify allowed parameters explicitly, e.g. url_for(params.permit(:foo, :bar)). Rails 7.1+ url_for(path_params: request.path_parameters, params: request.query_parameters) Rails versions before...

makandra dev

...and will return an enumerator. This is what allows you to do things like ['foo', 'bar', 'baz'].each.with_index.collect { |name, index| name * index } # -> ["", "bar", "bazbaz"] If you write your own each...

mysqlperformanceblog.com

...index when your query is well-formed: mysql> EXPLAIN SELECT * FROM users WHERE email = 'foo@example.com'; +----+-------------+-------+-------+----------------------+----------------------+---------+-------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------+----------------------+----------------------+---------+-------+------+-------+

makandra dev

...using Capybara, functions like click_link or expectations like expect(page).to have_css('.foo') already retry internally. See other card for in depth explanation At makandra we use Spreewald...

...with a GET request, even if the requesting method is PATCH or DELETE: def foo redirect_to '/bar', status: :see_other end See Modern HTTP Status codes for redirecting for...