R
rantingrick
Hello,
I am having trouble understanding the difference between require and
include. Also i need to know how to import a certain function or class
into my current namespace.
Now before i go any further i should explain that i am a Python
programmer and i understand that whilst Ruby and Python share some
similarities there are major differences between the languages, and
that is what seems to have me stumped here.
In python we use the "import" statement to bring modules, functions,
whatever. And the import statement can function in many ways,
observe...
if i want to bring all the names from the math module into my current
namespace without the need to qualify the names i can say...(note:
dir() shows the current namespace!)
'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil',
'copysign', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'factorial',
'floor', 'fmod', 'frexp', 'fsum', 'hypot', 'isinf', 'isnan', 'ldexp',
'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin',
'sinh', 'sqrt', 'tan', 'tanh', 'trunc']5.0
Now if i want to just use a certain function, class, constant, i can
call for just those specific names like...
Now if i want to bring a reference to the module in and then qualify
every thing within the module by perpending the
"module_name.identifier" i can say...
Ok, i know Ruby is different, so tell me how i do the same thing only
in Ruby terms. Specifically i need to bring in a function that resides
in a module in a different file. How do i do this?
I am having trouble understanding the difference between require and
include. Also i need to know how to import a certain function or class
into my current namespace.
Now before i go any further i should explain that i am a Python
programmer and i understand that whilst Ruby and Python share some
similarities there are major differences between the languages, and
that is what seems to have me stumped here.
In python we use the "import" statement to bring modules, functions,
whatever. And the import statement can function in many ways,
observe...
if i want to bring all the names from the math module into my current
namespace without the need to qualify the names i can say...(note:
dir() shows the current namespace!)
['__builtins__', '__doc__', '__name__', '__package__', 'acos',dir() ['__builtins__', '__doc__', '__name__', '__package__']
from math import *
dir()
'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil',
'copysign', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'factorial',
'floor', 'fmod', 'frexp', 'fsum', 'hypot', 'isinf', 'isnan', 'ldexp',
'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin',
'sinh', 'sqrt', 'tan', 'tanh', 'trunc']5.0
Now if i want to just use a certain function, class, constant, i can
call for just those specific names like...
dir() ['__builtins__', '__doc__', '__name__', '__package__']
from math import hypot, pi
dir() ['__builtins__', '__doc__', '__name__', '__package__', 'hypot', 'pi']
pi 3.1415926535897931
hypot(3,4) 5.0
Now if i want to bring a reference to the module in and then qualify
every thing within the module by perpending the
"module_name.identifier" i can say...
5.0import math
dir() ['__builtins__', '__doc__', '__name__', '__package__', 'math']
math.hypot(3,4)
Ok, i know Ruby is different, so tell me how i do the same thing only
in Ruby terms. Specifically i need to bring in a function that resides
in a module in a different file. How do i do this?