Advertisement
Guest User

Untitled

a guest
Jan 17th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. ------------------------------------------------- Module#module_function
  2. module_function(symbol, ...) => self
  3. ------------------------------------------------------------------------
  4. Creates module functions for the named methods. These functions may
  5. be called with the module as a receiver, and also become available
  6. as instance methods to classes that mix in the module. Module
  7. functions are copies of the original, and so may be changed
  8. independently. The instance-method versions are made private. If
  9. used with no arguments, subsequently defined methods become module
  10. functions.
  11.  
  12. module Mod
  13. def one
  14. "This is one"
  15. end
  16. module_function :one
  17. end
  18. class Cls
  19. include Mod
  20. def callOne
  21. one
  22. end
  23. end
  24. Mod.one #=> "This is one"
  25. c = Cls.new
  26. c.callOne #=> "This is one"
  27. module Mod
  28. def one
  29. "This is the new one"
  30. end
  31. end
  32. Mod.one #=> "This is one"
  33. c.callOne #=> "This is the new one"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement