Why word 'translate' is messing irb?
It is a bug in YARV that was fixed in YARV 2.4.0.
The commit message mentions the following workaround if you don't have YARV 2.4.0:
class << RubyVM::InstructionSequence
def translate; end
undef translate
end
Note that other implementations are not affected, only YARV.
What is translate keyword do in Ruby
Each Ruby syntax highlighting library often includes common phrases that are used in things like Rails. For example, belongs_to
, while not a special keyword in a Ruby sense, is very common in Rails applications so it's often highlighted.
translate
might be a special phrase as well as it's used by a lot of I18N libraries.
The only way to find out for sure is to look at the rules for syntax highlighting your editor uses. Usually there's a list of special method names in there.
Ruby doesn't recognize `downcase` or `split` as defined methods?
If returns a blank string because you don't return anything inside the collect!
block. Return word
and it will work :
def translate phrase
phrase = phrase.downcase.split(/ /)
phrase.collect! do |word|
word = word.split(//)
switched = false
while switched == false
word.each_index do |letter|
if word[letter] == ("a" || "e" || "i" || "o" || "u")
switched = true
word = (word[letter..-1] + word[0..(letter-1)]).join + "ay"
end
end
end
word
end
return phrase.join(" ")
end
puts translate("chocolate cream")
#=> atechocolay amcreay
It doesn't look like it's returning exactly what you expected, but it's still better than a blank string.
As for your weird error message in the console, it seems to be specific to the REPL (possibly because of the method name translate
).
How to parse week and year with strptime
I think that you need to use the commercial
method.
require 'date'
week = 20
start_week = Date.commercial(2020, week)
# => Mon, 11 May 2020
puts "#{start_week}"
# => 2020-05-11
In case you need a Range, you can do:
Date.commercial(2020, week).all_week
# => Mon, 11 May 2020..Sun, 17 May 2020
For more information see the documentation.
Related Topics
Ruby 'Pg' Gem Linking to Wrong Copy of Libpq.5.Dylib (On Osx)
Rmagick Installation: Can't Find Magickwand.H
How to Capitalize the First Letter in a String in Ruby
Rails Mapping Array of Hashes Onto Single Hash
Rubocop: Line Is Too Long ← How to Ignore
Rails: How to Make Date Strftime Aware of the Default Locale
What Does the "Yield" Keyword Do in Ruby
Make Rake Task from Gem Available Everywhere
Recommended Approach to Monkey Patching a Class in Ruby
How to Login a User with Devise
Ruby Use Array Tvalues to Index Nested Hash of Hash
How to Step Out of a Loop with Ruby Pry
All Ruby Tests Raising: Undefined Method 'Authenticate' for Nil:Nilclass
If String Is Empty Then Return Some Default Value
Capybara: Select an Option by Value Not Text
Why Is It Best to Store a Telephone Number as a String VS. Integer
Why Does Ruby Open-Uri's Open Return a Stringio in My Unit Test, But a Fileio in My Controller