Guest User

Untitled

a guest
Jan 16th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. class MyClass
  2. def initialize(plugin_name=nil)
  3. end
  4.  
  5. def method_missing(method_name)
  6. "#{plugin_name}".send(method_name)
  7. end
  8. end
  9.  
  10. class Logger
  11. def initialize(store)
  12. @store = store
  13. end
  14.  
  15. def info(message)
  16. @store.write(:info, message)
  17. end
  18. end
  19.  
  20. class StandardOutputStore
  21. def write(level, message)
  22. puts "#{level}: #{message}"
  23. end
  24. end
  25.  
  26. class FileStore
  27. def initalize(filename)
  28. @filename = filename
  29. end
  30.  
  31. def write(level, message)
  32. File.open(@filename, "a") do |file|
  33. file.write("#{level}: #{message}")
  34. end
  35. end
  36. end
  37.  
  38. logger = Logger.new(StandardOutputStore.new)
  39. logger.warn "hello"
  40.  
  41. logger = Logger.new(FileStore.new("/tmp/log"))
  42. logger.warn "hello"
  43.  
  44. module Plugins
  45. module Emoticons
  46. def smile
  47. ":-)"
  48. end
  49. end
  50. end
  51.  
  52. Dir["/plugins/*.rb"].each {|file| require file }
  53.  
  54. Plugins.constants.each do |constant|
  55. mod = Plugins.const_get constant
  56. TemplateMethods.send(:include, mod)
  57. end
Add Comment
Please, Sign In to add comment