...this object. Here are some tools to do so: Relevant methods @object.methods - Object.instance_methods returns a list of methods excluding methods inherited from Object. This makes the methods list drastically...

...filters the list of method names with a regular expression. Instance variables @object.instance_variables returns all instance variables defined on the object. Access them with @object.instance_variable_get :@varname, modify...

...probably only care about seconds. This means that two consecutive calls of Time.now probably return two inequal values. Consider freezing time in your tests so it is not dependent on...

Rails extends Time with a method #end_of_day which returns the latest possible Time on the same day. The exact value for this is...

...implemented both a version for loaded Ruby objects (Interval#overlaps?) and a scope that returns all overlapping intervals (Interval.overlapping). Depending on your problem you might need one or both or...

...this interval def overlaps?(other) start_date <= other.end_date && other.start_date <= end_date end # Return a scope for all interval overlapping the given interval, excluding the given interval itself

web.archive.org

...falls back to a COUNT query count If a counter cache is set up, returns the cached value Issues a COUNT query else Caveats If you trigger a COUNT query...

...assertion. Using .size avoids this problem. length Loads all records from the database, then returns the number of elements

...can, don't permit! everything but permit only known good keys. Use request.path_parameters returns a Hash with all parameters relevant for building a path with e.g. url_for (excluding...

...and similar). Note that it does not include query parameters. Use params.to_unsafe_h returns a HashWithIndifferentAccess with everything from params. If none of the above was enough for you...

...Makes a color less saturated. grayscale($color) Converts a color to grayscale. complement($color) Returns the complement of a color. invert($color) Returns the inverse of a color...

makandra dev

...In the example above, there will be the local variable weather_counter defined, which returns a counter of the currently rendered item in the collection. Furthermore it will add a...

...One can avoid ifs and any? calls in templates and make use of the return value of render. <%= render(@collection) || render('empty_state') %> Caching collections Fragment caching a rendered collection...

...scrollable element for the main viewport. On Chrome, Firefox and modern Safari, document.scrollingElement will return the element. The behavior varies on legacy browsers that we no longer support:

...versions, document.scrollingElement will return the element. On the legacy Edge engine (EdgeHTML), document.scrollingElement will return the element. IE11 does not support document.scrollingElement, but you can assume its . Setting overflow-y...

...attached files to config/initializers. It gives your strings a method #to_sort_atoms that returns an object that compares as expected. You can now say: ["Schwertner", "Schöler"].sort_by(&:to...

...of #to_sort_atoms: describe String do describe '#to_sort_atoms' do it 'should return an object that correctly compares German umlauts' do expect('Äa'.to_sort_atoms <=> 'Az'.to...

makandra dev

...Version uploader and original uploader can be distinguished by checking #version_name: version uploaders return the version name, whereas the original uploader instance returns nil Version instances do not have...

makandra dev
api.rubyonrails.org

...record, as well as to query the record for registered errors. This object is returned when calling .errors: errors = @user.errors # => # Here are some helpful messages of its API: [ ]

...error message from the locale files. get( ) (Almost) an alias of []. Calls messages[ ] and returns an array of error messages for that attribute. include?( ) Returns whether there is an error...

...an array with a block that is called with each element. The block must return a [key, value] tuple. This is useful if both the hash key and value can...

...a block. The block is called for each element in the array and should return a 2-tuple where the first element is the key and the second element is...

def __init__(self): GObject.Object.__init__(self) def get_background_items(self, window, file): """Returns the menu items to display when no file/folder is selected (i.e. when right-clicking the...

...file.is_directory() and file.get_uri_scheme() == "file": if os.path.exists(TERMINAL_PATH): items += [self._create_terminal_item(file)] return items def _setup_gettext(self): """Initializes gettext to localize strings.""" try: # prevent a possible exception...

...string properties and a function property: let user = { firstName: 'Max', lastName: 'Muster', fullName: function() { return this.firstName + ' ' + this.lastName } } user.fullName() // => 'Max Muster' In ES6 we can define a function property using the...

...following shorthand syntax: let user = { firstName: 'Max', lastName: 'Muster', fullName() { return this.firstName + ' ' + this.lastName } } user.fullName() // => 'Max Muster' We can also define a getter inside the object literal, without using Object.defineProperty():

...it considers your connection to be offline. async function isOnline({ path, timeout } = {}) { if (!navigator.onLine) return false path ||= document.querySelector('link[rel*=icon]')?.href || '/favicon.ico' timeout ||= 6000 const controller = new AbortController()

...timeoutTimer = setTimeout(() => controller.abort(), timeout); try { await fetch(path, { cache: 'no-store', signal: controller.signal }) return true } catch(error) { return false } finally { clearTimeout(timeoutTimer) } } Limitations of built-in navigator.onLine

...it now looks like this: class BaseUploader module DoesStrictTypeValidations as_trait do def revalidate(*) return unless file check_content_type_allowlist!(file) # This was check_content_type_whitelist! before

...versions have not been initialized by store!, their file methods will at this point return nil. You most likely want to remove these stale files as soon as a new...

...method to detect the end of the scrolling animation. Methods like scrollTo() don't return a promise. We may eventually get a scrollend event, but that is still some time...

Until then I'm using the following awaitScrollEnd() function as a workaround. It returns a promise that resolves when the given Document or Element does not receive a scroll...

makandra dev
unpoly.com

Unpoly 3.11.0 is a big release, shipping many features and quality-of-life improvements requested by the community. Highlights include...

...the end goal is clearly described and sufficient context is provided. Example Create notification.resolver.ts: Return the state$ property from the notification service: Use an async resolver; Update overview.component.ts: Replace injected...

...same applies for providing expected types, for example of a function signature or the return value. Information-Dense Keywords Actions: create, update, delete, edit, mirror, move, replace, refactor, add, ...

makandra dev
gist.github.com

...n] -- Steps into blocks or methods n times. If you accidentally stepped, you can return with finish 1. next [n] -- Runs n lines of code within the same frame

...find out the numbers finish [n] -- Runs the program until the n-th frame returns up -- Moves to a higher frame in the stack trace down -- Moves to a lower...

Unit test with error describe UsersHelper do describe '#user_display_name' do it 'returns the first and last name of a user' do user = FactoryBot.create(:user) allow(helper).to...

...receive(:current_user).and_return(user) expect(helper.user_display_name).to eq('Jim Knopf') end end end Error: does not implement: current_user Solutions RSpec >= 3.6 Unit test fixed with...

...metadata enabled (default since Rails 6). On mismatching purpose, #decrypt_and_verify will simply return nil. def decrypt_session_cookie(cookie_string) return if cookie_string.blank? cipher = ActiveSupport::MessageEncryptor.default_cipher

makandra dev
github.com

...Relation#traverse_association(*names) Edge Rider gives your relations a method #traverse_association which returns a new relation by "pivoting" around a named association. You can traverse multiple associations in...

...users WHERE sites.user_id = sites.id AND users.name = 'Bruce' It now uses these IDs to return a new relation that has no joins and a single condition on the id column...

...between the two methods is that unresolvable constants raise an error with constantize, but return nil with safe_constantize. If you validate the input string against an allowlist, an error...

...not correspond to a valid constant or if the constant is not accessible, it returns nil: "String".safe_constantize # => String "NonExistentClass".safe_constantize # => nil "Module::ExistingClass".safe_constantize # => Module::ExistingClass...