2012年7月11日水曜日

開発環境

『Learning Ruby』(Michael Fitzgerald 著、O'Reilly Media、2007年、ISBN978-0-596-52986-4)の Chapter 7(Hash)Review Questions 6を解いてみる。

その他参考書籍

6.

Nothing

コード(TextWrangler)

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

h = {'a' => 1,'b' => 2}

['a','b','c',1,2].each do |s|
  puts "#{h.has_key? s} #{h.key? s}"
end

入出力結果(Terminal)

$ ri Hash.has_key? >> tmp.txt
$ cat tmp.txt
---------------------------------------------------------- Hash#has_key?
     hsh.has_key?(key)    => true or false
     hsh.include?(key)    => true or false
     hsh.key?(key)        => true or false
     hsh.member?(key)     => true or false
------------------------------------------------------------------------
     Returns +true+ if the given key is present in _hsh_.

        h = { "a" => 100, "b" => 200 }
        h.has_key?("a")   #=> true
        h.has_key?("z")   #=> false

$ ./sample.rb
true true
true true
false false
false false
false false
$

0 コメント:

コメントを投稿