Tokyo "Many of the core contributors like Koichi Sasada, Shyouhei Urabe, Yui Naruse, Zachary Scott and Akira Matsuda live within 10-15 minutes of each other" https:/ /appfolio-engineering.squarespace.com/appfolio- engineering/2017/5/24/how-is-ruby-different-in-japan
Creates some publicly callable intermediate methods `foo_with_bar` and `foo_without_bar` in the example above Behavior of these methods are unpredictable
foo() p:foo; end def foo_with_bar() foo_without_bar; p:bar; end alias_method_chain :foo, :bar end p C.instance_methods(false) #=> [:foo, :foo_with_bar, :foo_without_bar]
'active_support/core_ext/module/aliasing' class C def foo() p:foo; end def foo_with_bar() foo_without_bar; p:bar; end alias_method_chain :foo, :bar # defining bar first, then baz def foo_with_baz() foo_without_baz; p:baz; end alias_method_chain :foo, :baz end C.new.foo_without_bar #=> :foo
require 'active_support/core_ext/module/aliasing' class C def foo() p:foo; end def foo_with_baz() foo_without_baz; p:baz; end alias_method_chain :foo, :baz # swapping the definition order of bar and baz def foo_with_bar() foo_without_bar; p:bar; end alias_method_chain :foo, :bar end C.new.foo_without_bar #=> :foo, :baz
`foo()` method with AMC The "bar" plugin defines a public method `foo_without_bar` But the behavior is unpredictable The behavior depends on the order of plugin loading order So, if you change the sort order in Gemfile, the behavior would change
require 'active_support/core_ext/module/aliasing' class C def foo() p:foo; end end # AMC first class C def foo_with_bar() foo_without_bar; p:bar; end alias_method_chain :foo, :bar end # Then prepend module M def foo() super; p:baz; end end C.send :prepend, M C.new.foo #=> :foo, :bar, :baz
def foo() p:foo; end end # prepend first module M def foo() super; p:baz; end end C.send :prepend, M # Then AMC class C def foo_with_bar() foo_without_bar; p:bar; end alias_method_chain :foo, :bar end C.new.foo #=> stack level too deep
`Array#orig_sum` method Although it was an internal method for calculating `Array#sum` The method used to be visible to all Active Support users Refinements made it perfectly "file scoped"
refine Object do def foo() p 'hello'; end end } # Then calling the method defined in the refinement class Object def bar() foo; end end Object.new.bar #=> "hello"
class Object def bar() foo; end end # Then define the actual method definition in a refinement using Module.new { refine Object do def foo() p 'hello'; end end } Object.new.bar #=> doesnot_work.rb:2:in `bar': undefined local variable or method `foo' for #<Object:0x007f8f2a0251c8> (NameError)
for creating a library-internal "super private" method But when you define a private method, you usually put it below the public methods, right? However, refinements definition has to be put at the top of the file
per each component Making sure that tests didn't break per each component Adding `:doc:` to all previously `protected` methods Last year, for Rails 5.1
changed it to return the defined method name in Symbol https:/ /github.com/ruby/ruby/commit/0f0b60ea86 `private` (`protected`, `public`) takes a Symbol and changes the method's visibility The patch was written in August 2013
`private` (`protected`, `public`) prefix was changing the scope of all following methods It breaks the Rails API document https:/ /github.com/rdoc/rdoc/issues/355
looks miserable The argument list becomes like "options as any Hash", or even "*args" It tells nothing unless we write a thorough documentation comment So hard for this non-statically typed language
The behavior becomes more strict (invalid keys, missing keys, etc.) Runs faster (in most cases, I guess) Creates less garbage objects (maybe) The method definition becomes a great documentation (most important IMO)
https:/ /github.com/amatsuda/rails/tree/ kwargs Back in Jan. 2013 Before Ruby 2.0.0 stable release In order to experiment the new feature in a real codebase
faster Makes the code more readable And generates a better API document Rails master now supports only >= 2.1 (actually 2.2.2) that does have `local_variable_get`
Such as server OS encoding, DB encoding, program file encoding, HTTP request encoding, URL encoding, Cookie encoding Rails is a web framework, and the recent web defacto encoding is UTF-8 Rails deals with YAML and JSON files, both of which supports only UTF (usualy UTF-8)
uses any other encoding than UTF-8, even in Japan I'm willing to drop multiencodings support from Action View I told this last year, but still I haven't published a patch I'm sorry, I'm so lazy...
can do everything using the language core features We can remove unicode_tables.dat from Active Support Smaller gem size Faster boot time Less memory consumption Multibyte chars handling will become faster Because it's implemented in C in Ruby No longer need to maintain that misterious code in Active Support
can't be completely removed in Rails 5 But we can use Ruby native implementation if RUBY_VERSION >= '2.4' We made a PR for this already https:/ /github.com/rails/rails/pull/28067
2015 To be more accurate, I proposed to reconsider akr's proposal once rejected in 2013 https:/ /bugs.ruby-lang.org/issues/ 8976#note-30 The proposal was accepted, and included in Ruby 2.3
Active Support version The Ruby version ignores non- numeric value It's OK because Ruby is a general purpose language, while Active Support is "web specific" language extension
Rubies that have and don't have `sum` `sum` is defined on both Enumerable and Array, where `Enumerable < Array` Native `sum` is faster, so it's preferrable because it's written in C Even if there's native `sum`, it has to fall back to `super` on non-numeric value It takes an argument It takes a block
Be Used In The Rails Codebase Because Rails master still supports 2.2 But you can use them in your apps! Update your production Ruby version to the newest stable, and start using these features now! There's no reason to stay on old version of Ruby
also getting better Ruby and Rails are in a very good relationship I'm having fun working on both projects There're always so many things to do because both Ruby and Rails are always changing I hope you to join us if you're interested!