赞 | 5 |
VIP | 620 |
好人卡 | 38 |
积分 | 69 |
经验 | 125468 |
最后登录 | 2015-7-27 |
在线时间 | 1666 小时 |
Lv4.逐梦者
- 梦石
- 0
- 星屑
- 6855
- 在线时间
- 1666 小时
- 注册时间
- 2008-10-29
- 帖子
- 6710
|
也不知道怎么的.
昨天晚上躺在床上准备睡觉的时候莫名其妙的就想到了这个帖子.
然后就莫名其妙的想到了这个方法.不知道可不可行.
除了 整数 类的对象在 RGSS 里是唯一的外.
符号 类的对象也是唯一的.
起初是用的数组的 pack("ll") 后 to_sym 弄成 符号
然后就改用 Marshal.dump 后再 to_sym
- class Point < Array
- def initialize(x, y)
- super(2)
- self[0] = x
- self[1] = y
- end
- def x
- return self[0].nil? ? 0 : self[0]
- end
- def y
- return self[1].nil? ? 0 : self[1]
- end
- def hash
- if @hash.nil?
- @hash = Marshal.dump(self)
- @hash.gsub!("\0"){ "hzhj" }
- @hash = @hash.to_sym
- end
- return @hash
- end
- end
- h = {}
- h[Point.new(1, 1).hash] = 1
- h[Point.new(1, 1).hash] = 2
- h[Point.new(1, 1).hash] = 3
- h[Point.new(1, 1).hash] = 4
- h[Point.new(1, 0).hash] = 11
- h[Point.new(1, 0).hash] = 12
- h[Point.new(0, 1).hash] = 13
- h[Point.new(0, 1).hash] = 14
- h[Point.new(2, 0).hash] = 15
- h[Point.new(2, 0).hash] = 16
- h[Point.new(0, 2).hash] = 17
- h[Point.new(0, 2).hash] = 18
- h[Point.new(0b10001000100010001000, 0b10011001100110011001).hash] = 19
- h[Point.new(0b10001000100010001000, 0b10011001100110011001).hash] = 20
- h[Point.new(0b10001000100010001000, 0b10011001100110011000).hash] = 21
- h[Point.new(0b10001000100010001000, 0b10011001100110011000).hash] = 22
- h[Point.new(0b10001000100010001000101010101010,
- 0b10011001100110011001100110011001).hash] = 23
- h[Point.new(0b10001000100010001000101010101010,
- 0b10011001100110011001100110011001).hash] = 24
- p h[Point.new(1, 1).hash],Point.new(1, 1).hash,
- h[Point.new(1, 0).hash],Point.new(1, 0).hash,
- h[Point.new(0, 1).hash],Point.new(0, 1).hash,
- h[Point.new(2, 0).hash],Point.new(2, 0).hash,
- h[Point.new(0, 2).hash],Point.new(0, 2).hash,
- h[Point.new(0b10001000100010001000, 0b10011001100110011001).hash],
- Point.new(0b10001000100010001000, 0b10011001100110011001).hash,
- h[Point.new(0b10001000100010001000, 0b10011001100110011000).hash],
- Point.new(0b10001000100010001000, 0b10011001100110011000).hash,
- h[Point.new(0b10001000100010001000101010101010,
- 0b10011001100110011001100110011001).hash],
- Point.new(0b10001000100010001000101010101010,
- 0b10011001100110011001100110011001).hash
- exit
复制代码 |
|