IceDragon200

SomeRubyStuff

Jul 10th, 2011
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.03 KB | None | 0 0
  1. # // Onbound Methods
  2. =begin
  3. class Onbound
  4.  
  5.   def put_cookies
  6.     print "Cookies"
  7.   end  
  8.   $cookies = self.instance_method(:put_cookies)
  9.  
  10. end  
  11.  
  12. class Onbound2 < Onbound
  13.  
  14.   def put_cookies
  15.     print "Moar Cookies"
  16.   end
  17.  
  18. end
  19.  
  20. Onbound.new.put_cookies
  21. $cookies.bind(Onbound.new).call
  22. Onbound2.new.put_cookies
  23. $cookies.bind(Onbound2.new).call
  24. =end
  25.  
  26. # // Proc Class Replica
  27. =begin
  28. class Proc_Replica
  29.  
  30.   def initialize(&block)
  31.     @___block = block
  32.     class << self
  33.       define_method(:call) do |*args|
  34.         @___block.call(*args)
  35.       end  
  36.     end  
  37.   end
  38.  
  39. end  
  40.  
  41. pro = Proc_Replica.new { |something| print something }
  42. pro2 = Proc_Replica.new { |a, b| print a+b }
  43.  
  44. pro.call("Something")
  45. pro2.call(1, 2)
  46. =end
  47.  
  48. # // Err Eval
  49.  
  50. =begin
  51. class ModTest
  52.  
  53.   class_eval <<-EOM
  54.     def self.print_cookies
  55.       print "Cookies"
  56.     end  
  57.   EOM
  58.  
  59. end  
  60.  
  61. ModTest.print_cookies
  62. =end
  63.  
  64. # // Struct
  65. =begin
  66. str = Struct.new(:wtf, :htf)
  67. strt = str.new(0, 1)
  68. strt.each { |p| print p }
  69. =end
Advertisement
Add Comment
Please, Sign In to add comment