2022-11-08
2010-12-31
macOSXでpathの通し方
以下で設定したが再起動後になぜか反映されない・・
.bash_profile
.bashrc
.profile
で、以下に設定したらOKでした。参考まで!
/etc/paths
[参考]
Snow Leopard時代のパス管理術
.bash_profile
.bashrc
.profile
で、以下に設定したらOKでした。参考まで!
/etc/paths
[参考]
Snow Leopard時代のパス管理術
2010-10-13
javascriptでinput textの内容を表示
[例]以下のテキストボックスに値(xxxx)を表示するとき。javascript文は以下のとおり。
[javascript文]
<input id="store_longitude" name="store[longitude]" size="30" type="text" />
[javascript文]
<script type="text/javascript">
document.getElementById("store_longitude").value = xxxx;
</script>
2010-10-11
google map マウスホイールで拡大縮小
[目的]google map において、マウスホイールで拡大縮小できるようにする。
以下より参照
GoogleMapsをマウスホイールで拡大・縮小できるようにする
以下より参照
GoogleMapsをマウスホイールで拡大・縮小できるようにする
map.enableScrollWheelZoom();
google map 緯度経度取得
[目的]google mapでクリック地点の緯度経度を取得する。
以下から引用
geekなページ
以下から引用
geekなページ
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Google Maps JavaScript API Example - simple</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=aaaaa"
type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="map" style="width: 300px; height: 300px"></div>
<script type="text/javascript">
//<![CDATA[
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.441944, -122.141944), 13);
}
GEvent.addListener(map, 'click', function(overlay, point) {
if (point) {
document.getElementById("show_x").innerHTML = point.x;
document.getElementById("show_y").innerHTML = point.y;
}
});
//]]>
</script>
<P id="show_x"></P>
<P id="show_y"></P>
</body>
</html>
railsでgoogle mapを表示
[目的]rails3.0でgoogle mapを表示する。
[環境]rails3.0 + ruby1.8.7
(1)プロジェクト作成
rails new googlemap
(2)コントローラ作成
rails g controller maps index
(2)index.html.erbを編集。
script srcを追加。
rails s
[関連エントリ]
GoogleMapでマッシュアップの練習(Rails編) #2
[環境]rails3.0 + ruby1.8.7
(1)プロジェクト作成
rails new googlemap
(2)コントローラ作成
rails g controller maps index
(2)index.html.erbを編集。
<div id="map" style="width: 500px; height: 500px"></div>
<script type="text/javascript">
//<![CDATA[
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(38, 138), 5);
map.disableDragging();
}
GEvent.addListener(map, 'click', function(overlay, point) {
if (point) {
alert("x = " + point.x + ", y = " + point.y);
map.openInfoWindow(point,
document.createTextNode("openInfoWindow Test"));
}
});
//]]>
</script>
(3)application.html.erbを編集。script srcを追加。
<!DOCTYPE html>
<html>
<head>
<title>Googlemap</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAABWYMASZTPMzQMXu2alSa6xTvcRCYKSpWpPqDL-sNMuxVdHFI_BTd8zF9kdpV97QhhvGd0NWsQckXsw"
type="text/javascript"></script>
</head>
<body>
<%= yield %>
</body>
</html>
(4)サーバ起動rails s
[関連エントリ]
GoogleMapでマッシュアップの練習(Rails編) #2
2010-10-09
file_columnでファイルのアップデート
[目的]画像のアップデート
[環境]Rails3.0, ruby1.8.7
(1)ImageMagickのインストール
sudo port install ImageMagick
--あとは、関連エントリのそのまま実行
(2)プロジェクト作成
rails new file_column_test
(3)file_columnプラグインインストール
(4)パッチ適用
vendor/plugins/file_column/lib/file_column.rb
Rails.rootを変更。
(5)Gemfile修正
gem 'rmagick', :require => 'RMagick'
(6)bundle installを実行
bundle install
(7)scaffold雛形作成
rails g scaffold Entry name:string image:string
rake db:migrate
(8)model修正
app/models/entry.rb
(9)viewを修正。
app/views/entries/_form.html.erb
multipart、file_column_fieldに変更。
(10)view修正2
app/views/entries/show.html.erb
image_tagに変更。
(10)view修正3
app/views/entries/index.html.erb
image_tagに変更。
(11)サーバ起動
rails s
<関連エントリ>
篳篥日記 [Rails] ruby 1.9.2 + Rails 3.0 + file_column
http://d.hatena.ne.jp/hichiriki/20100927
[環境]Rails3.0, ruby1.8.7
(1)ImageMagickのインストール
sudo port install ImageMagick
--あとは、関連エントリのそのまま実行
(2)プロジェクト作成
rails new file_column_test
(3)file_columnプラグインインストール
cd file_column_test
rails plugin install git://github.com/tekin/file_column.git
(4)パッチ適用
vendor/plugins/file_column/lib/file_column.rb
Rails.rootを変更。
--- file_column.rb.orig 2010-09-28 00:54:44.000000000 +0900
+++ file_column.rb 2010-09-28 00:55:12.000000000 +0900
@@ -594,7 +594,7 @@
# default options. You can override these with +file_column+'s +options+ parameter
DEFAULT_OPTIONS = {
- :root_path => File.join(RAILS_ROOT, "public"),
+ :root_path => File.join(Rails.root, "public"),
:web_root => "",
:mime_extensions => MIME_EXTENSIONS,
:extensions => EXTENSIONS,
(5)Gemfile修正
gem 'rmagick', :require => 'RMagick'
(6)bundle installを実行
bundle install
(7)scaffold雛形作成
rails g scaffold Entry name:string image:string
rake db:migrate
(8)model修正
app/models/entry.rb
class Entry < ActiveRecord::Base
file_column :image,
:root_path => "#{Rails.root}/public/store",
:web_root => "store/",
:magick => {
:versions => {
:thumb => { :crop => "1:1", :size => "50x50" },
:middle => "150x150>",
:large => "480x480>"
}
}
end
(9)viewを修正。
app/views/entries/_form.html.erb
multipart、file_column_fieldに変更。
<%= form_for(@entry, :html => { :multipart => true }) do |f| %>
<% if @entry.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@entry.errors.count, "error") %> prohibited this entry from being saved:</h2>
<ul>
<% @entry.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :image %><br />
<%= file_column_field "entry", "image" %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
(10)view修正2
app/views/entries/show.html.erb
image_tagに変更。
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<%= @entry.name %>
</p>
<p>
<b>Image:</b>
<%= image_tag(url_for_image_column(@entry, "image", :middle)) if @entry.image %>
</p>
<%= link_to 'Edit', edit_entry_path(@entry) %> |
<%= link_to 'Back', entries_path %>
(10)view修正3
app/views/entries/index.html.erb
image_tagに変更。
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<%= @entry.name %>
</p>
<p>
<b>Image:</b>
<%= image_tag(url_for_image_column(@entry, "image", :middle)) if @entry.image %>
</p>
<%= link_to 'Edit', edit_entry_path(@entry) %> |
<%= link_to 'Back', entries_path %>
(11)サーバ起動
rails s
<関連エントリ>
篳篥日記 [Rails] ruby 1.9.2 + Rails 3.0 + file_column
http://d.hatena.ne.jp/hichiriki/20100927
2010-10-02
[Rails]migrationのやり方
(1)migrationファイルの作成
script/generate migration change_stores_latitude_to_float
(2)migrationファイルの修正
[コマンド一覧]
create_table(name, options)
drop_table(name)
rename_table(old_name, new_name)
add_column(table_name, column_name, type, options)
rename_column(table_name, column_name, new_column_name)
change_column(table_name, column_name, type, options)
remove_column(table_name, column_name)
add_index(table_name, column_name, index_type)
remove_index(table_name, column_name)
(3)migrate実行
[参考]
http://tech.feedforce.jp/railsmigration.html
http://ponk.jp/?p=2374
script/generate migration change_stores_latitude_to_float
(2)migrationファイルの修正
[コマンド一覧]
create_table(name, options)
drop_table(name)
rename_table(old_name, new_name)
add_column(table_name, column_name, type, options)
rename_column(table_name, column_name, new_column_name)
change_column(table_name, column_name, type, options)
remove_column(table_name, column_name)
add_index(table_name, column_name, index_type)
remove_index(table_name, column_name)
(3)migrate実行
[参考]
http://tech.feedforce.jp/railsmigration.html
http://ponk.jp/?p=2374
2009-05-31
[MAC]AppCleanerのインストール
AppCleanerとは、
MACのソフトをアンインストールするときに、関連ファイルを
同時に削除してくれるソフト。
(1)下記URLよりAppCleanerを取得する。
http://www.freemacsoft.net/
(2)インストール
①ダブルクリックでインストール開始
②aplicationフォルダに保存。
MACのソフトをアンインストールするときに、関連ファイルを
同時に削除してくれるソフト。
(1)下記URLよりAppCleanerを取得する。
http://www.freemacsoft.net/
(2)インストール
①ダブルクリックでインストール開始
②aplicationフォルダに保存。
2009-05-26
rails2.0でscaffoldを実行する。
$ ruby script/generate scaffold person name:string age:integer
<参考/引用>
・[技術][Ruby][Ruby on Rails]Rails 2.0のscaffoldを使ってみた
macOS X10.5.7にruby1.8.7+rails2.3.2をインストールする!
[目的]
・macOSX 10.5.7にruby1.8.7+rails2.3.2の開発環境を構築する。
(デフォルトruby 1.8.6なのでruby1.8.7をソースからインストールする。)
[環境]
Rails 2.3.2
Ruby 1.8.7
macOSX 10.5.7
[作業方法]
(1)XcodeTools他のインストール。
(付属のMac OS X Install Disc2 からインストール)
※インストール画面にて、WebObjectsをチェックし、
追加でインストールする。
(2)環境変数の設定
(3)Ruby1.8.7のインストール
1.8.7をソースからコンパイルして/usr/localにインストールする
http://www.ruby-lang.org/ja/downloads/
(4)gemのインストール
http://rubyforge.org/frs/?group_id=126
(4)rails 2.3.2をインストール
(5)sqlite3をインストール
(6)bash_profileの設定
※再起動後、rubyパスが1.8.6に
戻っていたため、上記設定を実行。
<参考/引用>
・Mac OS X 10.5.6(Leopard) にRuby on Rails インストール
・Mac OS X (10.4/Tiger)でSQLiteを使う際の注意点
・Ruby Install Guide::MacOS X
・macOSX 10.5.7にruby1.8.7+rails2.3.2の開発環境を構築する。
(デフォルトruby 1.8.6なのでruby1.8.7をソースからインストールする。)
[環境]
Rails 2.3.2
Ruby 1.8.7
macOSX 10.5.7
[作業方法]
(1)XcodeTools他のインストール。
(付属のMac OS X Install Disc2 からインストール)
※インストール画面にて、WebObjectsをチェックし、
追加でインストールする。
(2)環境変数の設定
%export PATH=/usr/local/bin:/opt/local/bin:/opt/local/sbin/:$PATH
%export MANPATH=/opt/local/man:/opt/local/share/man:$MANPATH
(3)Ruby1.8.7のインストール
1.8.7をソースからコンパイルして/usr/localにインストールする
http://www.ruby-lang.org/ja/downloads/
% curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
% tar zxvf ruby-1.8.7-p72.tar.gz
% cd ruby-1.8.7-p72
% ./configure --prefix=/usr/local --enable-shared --enable-pthread
% make
% sudo make install
% make clean
% ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9.4.0]
% which ruby
/usr/local/bin/ruby
(4)gemのインストール
http://rubyforge.org/frs/?group_id=126
% ftp http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz
% tar zxvf rubygems-1.3.1.tgz
% cd rubygems-1.3.1
% sudo ruby setup.rb
% gem -v
1.3.1
% which gem
/usr/local/bin/gem
(4)rails 2.3.2をインストール
% sudo gem install rails
% rails -v
Rails 2.3.2
% which rails
/usr/local/bin/rails
(5)sqlite3をインストール
SQLiteのインストール
% port install sqlite3
sqlite3-rubyのインストール
% gem install sqlite3-ruby
(6)bash_profileの設定
※再起動後、rubyパスが1.8.6に
戻っていたため、上記設定を実行。
% echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile
<参考/引用>
・Mac OS X 10.5.6(Leopard) にRuby on Rails インストール
・Mac OS X (10.4/Tiger)でSQLiteを使う際の注意点
・Ruby Install Guide::MacOS X
2009-02-13
2009-02-12
RailsのAPIドキュメント
[目的]
railsのAPIドキュメントをローカルから見たい。
[環境]
Rails 2.2.2
ActionMailer 2.2.2
Ruby 1.8.7
[方法]
(1)ドキュメントの生成
(2)確認
doc/api/index.htmlをブラウザーで開く。
[参考]
RailsのAPIドキュメントいろいろ
railsのAPIドキュメントをローカルから見たい。
[環境]
Rails 2.2.2
ActionMailer 2.2.2
Ruby 1.8.7
[方法]
(1)ドキュメントの生成
rake rails:freeze:gems
rake doc:rails
(2)確認
doc/api/index.htmlをブラウザーで開く。
[参考]
RailsのAPIドキュメントいろいろ
2009-02-11
RailsのActionMailerによるメール送信
[目的]
Gmailのsmtpを利用して、メールを送信する。
[環境]
Rails 2.2.2
ActionMailer 2.2.2
Ruby 1.8.7
ubuntu 8.04
[作業方法]
(1)TLSライブラリのインストール(gmailのsmtp認証用)
◆フォルダ
vendor/plugins/action_mailer_tls
vendor/plugins/action_mailer_tls/lib
◆ファイル
vendor/plugins/action_mailer_tls/init.rb
init.rbの中身
vendor/plugins/action_mailer_tls/lib/smtp_tls.rb
smtp_tls.rbの中身
(2)config/environments/development.rbにSMTPの設定追加
delevopment.rbの最後に追記
(3)ActionMailer modelの生成
(4)NotifyMailer modelの修正
(5)○○controllerにアクションの記述
(6)送信テスト
http://localhost:3000/xxx/mailにて送信出来るか確認。
[参考]
Ruby on Rails/ActionMailerでTLSを使ったメール送信
Gmailのsmtpを利用して、メールを送信する。
[環境]
Rails 2.2.2
ActionMailer 2.2.2
Ruby 1.8.7
ubuntu 8.04
[作業方法]
(1)TLSライブラリのインストール(gmailのsmtp認証用)
◆フォルダ
vendor/plugins/action_mailer_tls
vendor/plugins/action_mailer_tls/lib
◆ファイル
vendor/plugins/action_mailer_tls/init.rb
init.rbの中身
require_dependency 'smtp_tls'
vendor/plugins/action_mailer_tls/lib/smtp_tls.rb
smtp_tls.rbの中身
require "openssl"
require "net/smtp"
Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
check_auth_args user, secret if user or secret
sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
@socket = Net::InternetMessageIO.new(sock)
@socket.read_timeout = 60 #@read_timeout
@socket.debug_output = STDERR #@debug_output
check_response(critical { recv_response() })
do_helo(helodomain)
raise 'openssl library not installed' unless defined?(OpenSSL)
starttls
ssl = OpenSSL::SSL::SSLSocket.new(sock)
ssl.sync_close = true
ssl.connect
@socket = Net::InternetMessageIO.new(ssl)
@socket.read_timeout = 60 #@read_timeout
@socket.debug_output = STDERR #@debug_output
do_helo(helodomain)
authenticate user, secret, authtype if user
@started = true
ensure
unless @started
# authentication failed, cancel connection.
@socket.close if not @started and @socket and not @socket.closed?
@socket = nil
end
end
def do_helo(helodomain)
begin
if @esmtp
ehlo helodomain
else
helo helodomain
end
rescue Net::ProtocolError
if @esmtp
@esmtp = false
@error_occured = false
retry
end
raise
end
end
def starttls
getok('STARTTLS')
end
def quit
begin
getok('QUIT')
rescue EOFError
end
end
end
(2)config/environments/development.rbにSMTPの設定追加
delevopment.rbの最後に追記
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:authentication => :plain,
:user_name => 'xxxxxx@gmail.com',
:password => '******'
}
(3)ActionMailer modelの生成
>script/generate mailer NotifyMailer result
(4)NotifyMailer modelの修正
def result(sent_at = Time.now)
subject 'NotifyMailer#result'
recipients 'xxxx@xxxxx.xxxx' #とりあえずここ修正
from 'xxxx@xxxxxx.xxx' #とりあえずここ修正
sent_on sent_at
body :greeting => 'Hi,'
end
(5)○○controllerにアクションの記述
def mail
mail = NotifyMailer.create_result()
NotifyMailer.deliver(mail)
end
(6)送信テスト
http://localhost:3000/xxx/mailにて送信出来るか確認。
[参考]
Ruby on Rails/ActionMailerでTLSを使ったメール送信
2009-01-14
Gedit をtextmate風にアレンジ
Linux(Ubuntu)でRailsの開発環境はどのようにしていますか?
NetBeansはなんか重くてイヤだし、
Emacsは挫折したし、vimでプログラムは・・って感じなんですよ。
軽くて簡単に使えるIDEないかなって探してたところ、
Macではtextmateが良いみたいなことを発見。
linuxでは、geditをtextmate風にアレンジ
出来るそうですね.
http://warlockhandler.blogspot.com/2008/04/converting-gedit-into-textmate.html
※ちなみにWindowsでは、e-text editorらしいよ。
NetBeansはなんか重くてイヤだし、
Emacsは挫折したし、vimでプログラムは・・って感じなんですよ。
軽くて簡単に使えるIDEないかなって探してたところ、
Macではtextmateが良いみたいなことを発見。
linuxでは、geditをtextmate風にアレンジ
出来るそうですね.
http://warlockhandler.blogspot.com/2008/04/converting-gedit-into-textmate.html
※ちなみにWindowsでは、e-text editorらしいよ。
2008-05-20
Rubyで「ファイル逆から表示」
Rubyで「ファイル逆から表示」
ファイル出力を逆から表示するプログラムを作成してみました。
ログを整形するときにちょっとやってみようと・・
(例)
1
2
3
↓
3
2
1
reverse_lines.rb
実行
実行結果
参考
[Ruby][勉強会]第3章コマンドを作ろう
http://d.hatena.ne.jp/syou6162/20080206/1202258516
ファイル出力を逆から表示するプログラムを作成してみました。
ログを整形するときにちょっとやってみようと・・
(例)
1
2
3
↓
3
2
1
reverse_lines.rb
filename = ARGV[0]
file = open(filename)
info = Array.new
while text = file.gets do
info.push(text)
end
file.close
puts "original:"
puts info
puts "reverse:"
puts info.reverse
実行
$ruby reverse_lines.rb hoge.txt
実行結果
original:
1
2
3
reverse:
3
2
1
参考
[Ruby][勉強会]第3章コマンドを作ろう
http://d.hatena.ne.jp/syou6162/20080206/1202258516
Rubyで「ファイル情報出力」
カレントディレクトリのファイル情報を取得するプログラムを書いてみました。
file_info.rb
実行(hogeディレクトリの中のファイルを確認する)
実行結果
ファイル名、サイズ(バイト)、修正日の順に出力されます。
file_info.rb
Dir::glob("**/*.*").each {|f|
puts "#{f},#{File::stat(f).size},
#{File::stat(f).mtime.strftime("%Y/%m/%d %H:%M")} "
}
実行(hogeディレクトリの中のファイルを確認する)
$cd hoge
hoge>$ruby ../file_info.rb
実行結果
ファイル名、サイズ(バイト)、修正日の順に出力されます。
hoge1.txt,36,2008/05/20 10:10
hoge2.txt,203,2008/05/20 10:11
hoge3.txt,97,2008/05/20 10:11
2008-05-12
Rubyで「ファイルの内容消去」
Rubyでファイル内容を消去する方法がありましたので
メモっておきます。
erase_file.rbのソース
端末から実行します。
実行結果
[参考]ruby-talk-googleより
http://groups.google.co.jp/group/ruby-talk-google/browse_thread/thread/d3f54880a601b23f
PS:実際にはどのような使われ方するかはよく分からないけど。
ファイル削除して、もう一度ファイル作成するだけと思ったりもする。
メモっておきます。
erase_file.rbのソース
f = ARGV[0]
File.open(f,'w'){|file| file = nil}
端末から実行します。
$ruby erase_file.rb test.txt
実行結果
test.txtの内容が消去される。
(当然ですが、test.txtのファイルは残ったままで
中身だけが削除される。)
[参考]ruby-talk-googleより
http://groups.google.co.jp/group/ruby-talk-google/browse_thread/thread/d3f54880a601b23f
PS:実際にはどのような使われ方するかはよく分からないけど。
ファイル削除して、もう一度ファイル作成するだけと思ったりもする。
2008-05-09
Rubyで「データ整形」
試験データ作成に使えそうな
データ整形をメモっておきます。
◇zero suppress有り
例)10⇒0000000010
ソース
※やり方は、2つ。どちらでもOK。
実行結果
◇固定長(半角空白埋め)
例)
「10」⇒「########10」
「10」⇒「10########」
※「#」は「空白」と読み替えてください。
ソース
実行結果
◇半角から全角への変換
han2zen.rbのソース
端末から実行する。
※windowsのsjisエンコードの場合は、ruby -Ks とする。
実行結果
※全角に変換される。
[参考]
http://bbs.ddc.co.jp/mt/indesignbbs/archives/9507_20060709111700.html
データ整形をメモっておきます。
◇zero suppress有り
例)10⇒0000000010
ソース
i = 10
zero_i = i.to_s.rjust(10,"0")
puts zero_i
puts "%010d " % i
※やり方は、2つ。どちらでもOK。
実行結果
0000000010
0000000010
◇固定長(半角空白埋め)
例)
「10」⇒「########10」
「10」⇒「10########」
※「#」は「空白」と読み替えてください。
ソース
i = 10
sol_i1 = i.to_s.rjust(10," ")
sol_i2 = i.to_s.ljust(10," ")
puts sol_i1
puts sol_i2
puts "% 10d" %i
実行結果
10
10
10
◇半角から全角への変換
han2zen.rbのソース
require 'jcode'
s = ARGV[0]
puts s.tr('0-9A-Za-z-','0-9A-Za-zー')
端末から実行する。
$ruby -Ku han2zen.rb 1234567890abcdEFGH-
※windowsのsjisエンコードの場合は、ruby -Ks とする。
実行結果
1234567890abcdEFGHー
※全角に変換される。
[参考]
http://bbs.ddc.co.jp/mt/indesignbbs/archives/9507_20060709111700.html
Rubyで「ランダム生成」
乱数作成方法をメモ。
(1)1~3までの乱数
rand(3)+1
(2)0~3までの乱数
rand(4)
ソース
実行結果
(1)1~3までの乱数
rand(3)+1
(2)0~3までの乱数
rand(4)
ソース
10.times{
puts "(1): #{rand(3)+1} (2): #{rand(4)}"
}
実行結果
(1): 3 (2): 1
(1): 2 (2): 1
(1): 1 (2): 1
(1): 1 (2): 0
(1): 3 (2): 0
(1): 2 (2): 3
(1): 3 (2): 3
(1): 1 (2): 1
(1): 2 (2): 1
(1): 2 (2): 0
登録:
投稿 (Atom)