Skip to content

Instantly share code, notes, and snippets.

@kotp
Last active December 12, 2015 12:29
Show Gist options
  • Save kotp/4772181 to your computer and use it in GitHub Desktop.
Save kotp/4772181 to your computer and use it in GitHub Desktop.
Exploring modules, constants and methods
puts "Loading global_var.rb"
GlobalConstant = 'GlobalConstant'
$GlobalConstant_WithDollarSign = 'Global Constant with Dollar Sign'
module SharedVar
NAMESPACED_CONSTANT = 'Named spaced constant'
def your_method
"Whatever your method would be."
end
end
require './global_var'
include SharedVar
puts GlobalConstant
puts $GlobalConstant_WithDollarSign
puts SharedVar::NAMESPACED_CONSTANT
puts SharedVar::your_method
@Sasgho
Copy link

Sasgho commented Feb 12, 2013

hi Kotp, nice to meet you

so the example i send you, work..but when i try to send the last value setting of globalvalue..this is missed (don't hold the last value for new .rb file (33)) and return me the value 1..it's @Prueba = 1 for initialized

regards

@kotp
Copy link
Author

kotp commented Feb 12, 2013

Let me see if this is what we are talking about.

You really want to instantiate a instance method on a module that is not instantiable?

Can you show some code? You can use code markup here. Or you can do a hangout with me (accept the chat requests you should have received) or request one from me.

@DouglasAllen
Copy link

require_relative 'global_var'

unless you're building a gem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment