I've been getting into Ruby over the past few months, but one thing that I haven't figured out yet is what the Ruby equivalent of C#'s (and other languages) using
statement is.
I have been using the require
statement to declare my dependencies on Gems, but I am getting lazy and would prefer to not fully qualify my frequently used class names with their module (namespace) name.
Surely this is possible, right? I must not be using the right terminology as Google hasn't given me anything useful.
>> Math::PI
=> 3.14159265358979
>> PI
NameError: uninitialized constant PI
from (irb):3
>> include Math
=> Object
>> PI
=> 3.14159265358979
OTOH, if the issue is just aliasing class names, consider that, as they say "Class is an object, and Object is a class".
So:
>> require 'csv'
>> r = CSV::Reader
>> r.parse 'what,ever' do |e| p e end
["what", "ever"]
Yes, in Ruby the class name is just a reference like any other to an object of class Class
.
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