fork download
  1.  
  2. require "ostruct"
  3.  
  4. module Scarlet
  5. class << self
  6. def init ssss , mod , h
  7. h.each do | m , *h |
  8. next unless ssss.methods.include? m
  9. a = ssss.method( m ).call *h
  10. mod.define_singleton_method "#{m}".to_sym do | *h , &block | a.method( m ).call *h , &block end
  11. mod.define_singleton_method "#{m.to_s.delete('!?')}_".to_sym do a end
  12. end
  13. end
  14. end
  15. module Default
  16. def self.extended mod
  17. Scarlet.init self , mod , [
  18. [ :uniq_sym ] ,
  19. ]
  20. end
  21. def self.uniq_sym *h
  22. ru = Hash.new
  23. ru[:hs] = Hash.new
  24. a = OpenStruct.new ru
  25. a.define_singleton_method __method__ do | str = "misaka_" , n = rand(10000) |
  26. tmp = "#{str}_#{n}".to_sym
  27. if a.hs.keys.include? tmp
  28. return uniq_sym str , n + 1
  29. else
  30. a.hs.store( tmp , true )
  31. return tmp
  32. end
  33. end # singleton
  34. return a
  35. end # self
  36. end # Dfault
  37. end
  38.  
  39. module A
  40. extend Scarlet::Default
  41. end
  42.  
  43. p A.uniq_sym("test",1)
  44. p A.uniq_sym("test",1)
  45. p A.uniq_sym("rrrr",5)
  46. p A.uniq_sym("rrrr",4)
  47. p A.uniq_sym("rrrr",4)
  48.  
  49.  
Success #stdin #stdout 0.01s 4888KB
stdin
Standard input is empty
stdout
:test_1
:test_2
:rrrr_5
:rrrr_4
:rrrr_6