Created
September 15, 2011 20:58
-
-
Save guillermo/1220466 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22:55:19 guillermo@leuschnerdamm:/tmp/asdf ruby-1.9.2-p290 | |
$ rake install | |
Installing | |
Installing | |
22:56:07 guillermo@leuschnerdamm:/tmp/asdf ruby-1.9.2-p290 | |
$ rake install2 | |
WADUS WADUS | |
22:56:09 guillermo@leuschnerdamm:/tmp/asdf ruby-1.9.2-p290 | |
$ | |
The second method is only possible with newer version of rake. Old ones use top level binding to execute code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Require always use TOPLEVEL_BINDING | |
# so next method will be there | |
def install | |
puts "WADUS WADUS" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Option 1 | |
# The clean one, you can move the class to other file | |
module Utils | |
extend self | |
def install | |
puts "Installing" | |
end | |
end | |
desc "We are going to install... LA LA LA" | |
task :install do | |
Utils::install | |
Utils.install # You can use whatever you want | |
end | |
# Option 2 | |
# You can use a separete file. | |
$:.unshift(File.dirname(__FILE__)) # current dir is not included | |
require 'my_file' | |
desc "We are going to install... LA LA LA" | |
task :install2 do | |
TOPLEVEL_BINDING.instance_exec{ install } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment