Ruby projects by tracking and installing the exact gems and versions that are needed.Bundler is an exit from dependency hell, and ensures that the gems you need are present in development, staging, and production. Starting work on a project is as simple as bundle install https://bundler.io/ “ “ 14 / 85
a boolean value) should end in a question mark (i.e. Array#empty?). Methods that don’t return a boolean, shouldn’t end in a question mark. https://rubystyle.guide/#bool-methods-qmark “ “ 24 / 85
ENCODED_BLANKS = Concurrent::Map.new do |h, enc| h[enc] = Regexp.new(BLANK_RE.source.encode(enc), BLANK_RE.options | Regexp::FIXEDENCODING) end # A string is blank if it's empty or contains whitespaces only: # # ''.blank? # => true # ' '.blank? # => true # "\t\n\r".blank? # => true # ' blah '.blank? # => false # # Unicode whitespace is supported: # # "\u00a0".blank? # => true # # @return [true, false] def blank? # The regexp that matches blank strings is expensive. For the case of empty # strings we can speed up this method (~3.5x) with an empty? call. The # penalty for the rest of strings is marginal. empty? || begin BLANK_RE.match?(self) rescue Encoding::CompatibilityError ENCODED_BLANKS[self.encoding].match?(self) end end def present? # :nodoc: !blank? end end 58 / 85
? !!empty? : false end # An object is present if it's not blank. # # @return [true, false] def present? !blank? end end このクラスのメソッドは基本的にどこのクラスからも呼び出せる 67 / 85
record instance is an anti-pattern, to not say wrong. Making it faster is to legitimate that anti-pattern. https://github.com/rails/rails/issues/35059 “ “ 意訳すると『ActiveRecord では、そもそもpresent? やblank? を使うことがアンチ パターンです。それを高速化するということはアンチパターンを正当化すること になります。 』とのことです。 https://qiita.com/ham0215/items/b156d8cc5547ec56c719 “ “ 81 / 85