This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
private String _name // 名前 | |
private String _officeAreaCode; // 市外局番 | |
private String _officeNumber; // 電話番号 | |
public String getName() { | |
return _name; | |
} | |
public String getTelephoneNumber() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1日目 | |
# 文字列 "Hello,world" を出力する | |
puts "Hello,world" | |
# 文字列 "Hello,Ruby" から "Ruby" という単語のインデックスを検索する | |
puts "Hello,Ruby".index("Ruby") | |
# 自分の名前を10回出力する |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 一日目 | |
// ioは強い型付けか?弱い型付けか? | |
1 + 1 // => 2 | |
1 + "one" // => xception: argument 0 to method '+' must be a Number, not a 'Sequence' | |
// 答え:強く型付けされた言語 | |
// 0は真か偽か? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node v0.10.21 | |
"use strict"; | |
var zlib = require('zlib'); | |
var uncipherd_text = 'ひらぶん'; | |
console.log("source"); | |
console.log(uncipherd_text); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util'); | |
util.isJSON = function(str) { | |
try { | |
JSON.parse(str); | |
return true; | |
} catch (e) { | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'benchmark' | |
Benchmark.bm 10 do |r| | |
r.report "*" do | |
10000000.times { 2 * 2 } | |
end | |
r.report "<<" do | |
10000000.times { 2 << 1 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h = {} | |
120.times { | |
r = rand(6) | |
h[r] = h[r].nil? ? 0 : h[r] += 1 | |
} | |
p h | |
a = [] | |
e = 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 正規表現には、先読み(lookahead)と後読み(lookbehind)という機能がある | |
# 以下は住所から番地だけを抜き出す例 | |
pattern = /(?<=丁目)(\d+)(?=番地)/ | |
pattern.match('東京都新宿区市谷左内町21丁目13番地') # => #<MatchData "13" 1:"13"> | |
# 否定先読み(negative lookahead)と否定後読み(negative lookbehind)は、先読み/後読みの逆の動作 | |
pattern = /(?<!2012)-(?<month_and_day>\d{2}-\d{2})/ | |
pattern.match('2012-01-01') # => nil | |
pattern.match('2011-01-01') # => #<MatchData "-01-01" month_and_day:"01-01"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (?>)で囲むと、そこにマッチした部分でバックトラックを抑止することができる | |
# 次の場合は"ruby"にも"ruby5"にもマッチする | |
pattern = /(\w+)/ | |
pattern.match('ruby')[1] # => "ruby" | |
pattern.match('ruby5')[1] # => "ruby5" | |
# 「(\w+)」はが数字にもマッチするが、すると「[0-9]」がマッチするものがなくなってしまうので、 | |
# 「(\w+)」は"ruby"までしかマッチしない | |
pattern = /(\w+)[0-9]/ | |
pattern.match('ruby5')[1] # => "ruby" (書籍には => "ruby5" とあるが誤植) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# オプションは以下のように指定する | |
# mは「.」に改行もマッチさせ、iは大文字小文字の区別を行わない | |
/ruby/mi | |
%r{ruby}mi | |
# oは正規表現リテラルが評価された時、一度だけ式展開を行う | |
%w(foo bar).map {|str /#{str}/} # => [/foo/, /bar/] | |
%w(foo bar).map {|str /#{str}/o} # => [/foo/, /foo/] | |
# (?i)以降はiオプションが付与される |
OlderNewer