...its generators with Rails::Generators.invoke ARGV.shift, ARGV. From inside a Rails generator, you may call the inherited Thor method invoke(args=[], options={}, config={}). There also is a generate method which...

...will run the generator in a subprocess. Call it with generate 'generator_name', 'command line args'. Expected (hard-coded) directory structure of a generator #{generator namespace, e.g. rails}/ #{generator name...

makandra dev

When you call a method on an object, Ruby looks for the implementation of that method. It looks in the following places and uses the first implementation it finds:

include IncludedModule prepend PrependedModule def action puts "Klass" super end end ... and we call a method like this: instance = Klass.new instance.extend(SingletonModule) instance.action Then we get an output as...

makandra dev

...files for images, fonts etc. Most applications will use a single pack (we often call it main), some applications might for example use separate frontend and backend packs.

...yarn upgrade [package] yarn upgrade [package]@[version] yarn remove [package] Under the hood, Yarn calls npm for you. Do not use the npm command yourself. Do not manipulate package.json yourself...

makandra dev
developer.mozilla.org

...to abort async code is that your function takes a AbortSignal { signal } property. The caller can use this signal to send an abort request to your function. Upon receiving the...

...countDown() abortable Here is a variant of countDown() that may be canceled by the caller before the time has elapsed: function countDown(seconds, options = {}) { return new Promise((resolve, reject) => {

api.rubyonrails.org

...time, use travel: travel 1.day All those methods may also receive a block to call and restore time afterwards. If you don't provide a block, you must call travel...

relishapp.com

When you are using lambdas in RSpec to assert certain changes of a call, you know this syntax: expect { playlist.destroy }.to change { Playlist.count }.by(-1) While you can define multiple...

...playlist.destroy } .to change { Playlist.count }.by(-1) .and not_change { Video.count } The above example will call playlist.destroy only once, but test both assertions. Note When you chain multiple Capybara matchers using...

...nested_form.object will be nil. The :reject_if option lambda in your accepts_nested_attributes call is defined incorrectly. Raise the attributes hash given to your :reject_if lambda to see...

...for already iterates for you. You used form.fields_for |nested_form|, but continue to call form helpers (like text_field) on the containing form instead of nested_form.

Rails 3, 4, 5, 6 config/application.rb config/environment.rb before the initialize! call (we don't usually edit this file) The current environment, e.g. environments/production.rb Gems Vendored plugins All initializers in config/initializers...

config/environment.rb after the initialize! call (we don't usually edit this file) Your own code from app Rails 2 Code in config/preinitializer.rb (if it exists) environment.rb, code above the...

If you already selected an element and want to get its parent, you can call find(:xpath, '..') on it. To get the grand-parent element, call find(:xpath, '../..'). Example

github.com

...studies. It is based on an article written by Stephen Curtis. Table of Contents Call Stack Primitive Types Value Types and Reference Types Implicit, Explicit, Nominal, Structuring and Duck Typing...

...Operators, Type Arrays and Array Buffers DOM and Layout Trees Factories and Classes this, call, apply and bind new, Constructor, instanceof and Instances Prototype Inheritance and Prototype Chain Object.create and...

ruby-lang.org

...is a slightly abbreviated version: What changed When the last argument of a method call is a Hash, Ruby < 3 automatically converted it to to Keyword Arguments. If you call...

...in Ruby >= 3 that accepts keyword arguments, either explicitly or via **kwargs, you cannot call it with a hash. I.e. def explicit_kwargs(x:, y:) # ... end def splat_kwargs(**kwargs...

class Movie < ApplicationRecord normalizes :title, with: -> { _1.strip } end Tip Normalization lambdas are not called for nil values by default. To normalize nil values, pass an apply_to_nil: true...

...class Movie < ApplicationRecord normalizes :title, with: Normalizers::StripNormalizer end The with keyword accepts any callable object that takes the attribute’s value as its only argument. To comply with this...

...Support for combining structurally incompatible relations with and Pull request: Ignore joins on #and calls Alternative: Use SQL snippets When you call #where() with an SQL snippet string instead of...

...patch in routing-filter as it still expects an array of route data when calling super, but never actually calls the block that now needs to be called. Due to...

...this monkey patch.' end # We cannot prepend a custom extension module here because we call `super` in this method which should call the Rails # #find_routes-method and not the...

When you're nesting setTimeout(f, 0) calls, your browser will silently increase the delay to 5 milliseconds after the fourth level of nesting. This is called "timeout clamping" and...

...a similar note, all major browsers have implemented throttling rules for setInterval and setTimeout calls from tabs that are currently in the background. You can test it yourself by running...

jetbrains.com

RubyMine has a collaboration feature called "Code With Me". Using it, you can invite someone into your local editor to work together. This is nicer to the eyes and much...

...icon once a session is running. Features See other people's cursor Follow others Call others to follow you Work in full sync Work independently, but still in the same...

docs.ruby-lang.org

...method. return accepts a value that will be the return value of the method call. Use break to quit from a block and from the method that yielded to the...

...jump out of a block and returns nil or the provided argument to the caller. break # => SyntaxError: Can't escape from eval with break example { break 'break' } # => 'break'

github.com

...before continuing - the event could prevent the default behavior. Luckily there is a concept called passive event listeners which is supported by all modern browsers. Below are the key parts...

...analysis indicates that the majority of touch event handlers on the web never actually call preventDefault(), so browsers often block scrolling unnecessarily. By marking a touch or wheel listener as...

...provides a database-based model level mutex for MySQL. You use it by simply calling Lock.acquire('string to synchronize on') do # non-threadsafe code end You must make sure the...

...Only one process can enter the block using the same string, so a concurrent call to another Lock.acquire('string to synchronize on') will block, whereas Lock.acquire('some other string') will...

...it_should_act_like from our spec_candy.rb (note the /behave/act/). It allows you to call a standard shared example group with parameters. Some stupid examples follow to show how it...

it_should_act_like 'string equaling another string', :string => 'foo' end If you call it_should_act_like with a block, it will be made available as block:

makandra dev
github.com

...by "pivoting" around a named association. You can traverse multiple associations in a single call. E.g. to turn a relation of posts into a relation of all posts of their...

Relation#collect_ids You should not use relation.collect(&:id) for this because a call like that will instantiate a potentially large number of ActiveRecord objects only to collect its...

stackoverflow.com

...it, e.g. with the splat operator: args = [1,2,3] some_method(*args) # Ruby calls args.to_a here Implicit conversion Implicit conversion happens when Ruby tries to convert an object...

...when it thinks it should: a, b, c = args # Ruby calls args.to_ary here # Fictional example; Ruby decomposes the block argument by calling args.to_ary [args].each do |(x, y...

...name_prefix is used. (see full_table_name_prefix in ActiveRecord::ModelSchema). The relevant call to full_table_name_prefix happens in compute_table_name. And compute_table_name is...

...called only if no table_name has been defined for a class (see reset_table_name and table_name). This is why you might be tempted to fix the odd...

...is about valid files, e.g. matching extension white- or blacklists. "Processing" is about process calls, e.g. for changing image resolution. "Download" is when CarrierWave loads a file from a remote...

CarrierWave provides CarrierWave::Uploader::Base.clean_cached_files! for that already, but you need to call regularly from your preferred scheduler. For example, when using whenever, you should have something like...