首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >phash ruby,如何访问散列

phash ruby,如何访问散列
EN

Stack Overflow用户
提问于 2014-08-08 09:09:59
回答 1查看 716关注 0票数 0

目前,我开始使用phash (http://www.phash.org)和ruby (https://github.com/toy/pHash/blob/master/lib/phash.rb)相结合。

如果我使用所描述的例子,它是有效的。

但我只想提取哈希,但我不知道怎么做

代码语言:javascript
复制
#!/usr/bin/env ruby

require 'rubygems'
require 'phash'

a = Phash::Image.new(ARGV[0])
b = Phash::Image.new(ARGV[1])

puts "a="
#output => #<Phash::ImageHash:0x00000002947080>
puts a.phash

puts "b="
#output same ..=> #<Phash::ImageHash:0x00000002946ef0>
puts b.compute_phash

# works as expected if ARGV[0]=ARGV[1] => 1.0
puts a % b
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-08 10:46:01

您需要的是#data方法:

代码语言:javascript
复制
> h = Phash::Image.new(p).phash
=> #<Phash::ImageHash:0x00000002515f70 @data=18314200736077351885>
> h.class
=> Phash::ImageHash
> h.methods
=> [:similarity, :data, :length, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :singleton_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]
> h.data.class
=> Bignum
> h.data
=> 18314200736077351885
> h.data.to_s
=> "18314200736077351885"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25199813

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档