Is there any gem which adds # encoding: UTF-8
to each Ruby file automatically?
Or is there any other way to prevent from the invalid multibyte char (US-ASCII)
error in the entire Ruby on Rails project (not in a single class only)?
The #insert method in Ruby accepts an index position and a value as the arguments. You can use it to insert an element at any index position. In the example above, the insert method will “squeeze” the element into the specified array.
Use Array#inject to Sum an Array of Numbers in Ruby To calculate the sum of an array in Ruby versions before 2.4. 0, we must use inject or its alias reduce . inject is a function that takes an initial value and a block. The accumulation is the first block argument, and the current number is the second.
In Ruby, we use #concat to append a string to another string or an element to the array. We can also use #prepend to add a string at the beginning of a string.
Upgrade to Ruby 2.0, as it makes UTF-8 the default encoding, removing the need for magic comments.
Try magic_encoding gem, it can insert uft-8 magic comment to all ruby files in your app.
[EDIT] Having switched to SublimeText now I use auto-encoding-for-ruby plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With