Guest User

Untitled

a guest
Jul 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. class MyClass
  2. class<<self
  3. def new(*args)
  4. ret = if (args.size == 1 && args[0].kind_of?(String))
  5. obj = allocate
  6. obj.send(:initialize,*args)
  7. obj
  8. else
  9. false
  10. end
  11. end
  12. end
  13. def initialize string
  14. @my_name = string
  15. end
  16. end
  17.  
  18. puts MyClass.new(123).inspect # => false
  19. puts MyClass.new("hello").inspect # => #<MyClass:0x101071ed8 @my_name="hello">
Add Comment
Please, Sign In to add comment