When i import Time and HTTParty i got these warnings:
C:/Ruby27-x64/lib/ruby/2.7.0/time.rb:34: warning: already initialized constant Class::ZoneOffset
C:/Ruby27-x64/lib/ruby/2.7.0/Time.rb:34: warning: previous definition of ZoneOffset was here
C:/Ruby27-x64/lib/ruby/2.7.0/time.rb:137: warning: already initialized constant Class::LeapYearMonthDays
C:/Ruby27-x64/lib/ruby/2.7.0/Time.rb:137: warning: previous definition of LeapYearMonthDays was here
C:/Ruby27-x64/lib/ruby/2.7.0/time.rb:138: warning: already initialized constant Class::CommonYearMonthDays
C:/Ruby27-x64/lib/ruby/2.7.0/Time.rb:138: warning: previous definition of CommonYearMonthDays was here
C:/Ruby27-x64/lib/ruby/2.7.0/time.rb:475: warning: already initialized constant Class::MonthValue
C:/Ruby27-x64/lib/ruby/2.7.0/Time.rb:475: warning: previous definition of MonthValue was here
C:/Ruby27-x64/lib/ruby/2.7.0/time.rb:677: warning: already initialized constant Time::RFC2822_DAY_NAME
C:/Ruby27-x64/lib/ruby/2.7.0/Time.rb:677: warning: previous definition of RFC2822_DAY_NAME was here
C:/Ruby27-x64/lib/ruby/2.7.0/time.rb:681: warning: already initialized constant Time::RFC2822_MONTH_NAME
C:/Ruby27-x64/lib/ruby/2.7.0/Time.rb:681: warning: previous definition of RFC2822_MONTH_NAME was here
This is literally all the code:
require 'HTTParty'
require 'Time'
Somebody knows how i fix this?
There is no Time
library in Ruby. There is, however, a time
library.
It looks like you are using a case-insensitive file system, so when you require 'Time'
, the Operating System will "lie" to Ruby and tell it that Time.rb
actually exists, even though there is really only a time.rb
. (The OS will say the same thing about TIME.RB
or tImE.rB
or TiMe.Rb
or …)
Therefore, Ruby will load Time.rb
(which is really time.rb
). However, internally, the time
library will of course use require 'time'
everywhere. Now, Ruby detects when a file has already been loaded and will just ignore it, BUT Time.rb
and time.rb
are two different file names, so Ruby will naturally load them both.
Since they are the same file, though, everything in time.rb
will get executed twice, which means that you will get a warning for every single constant definition and every single method definition in that file.
The solution is simple: use require 'time'
because that's the name of the library's entry file.
The alternative would be to use a case-sensitive file system, in which case you would simply get a LoadError
exception telling you that there is no file named Time.rb
.