おもしろかったので

>> program = "puts 'hello world'"
=> "puts 'hello world'"
>> eval program
hello world
>> program.bytes.map {|byte| byte.to_s(2).rjust(8,'0')}
=> ["01110000", "01110101", "01110100", "01110011", "00100000", "00100111", "01101000", "01100101", "01101100", "01101100", "01101111", "00100000", "01110111", "01101111", "01110010", "01101100", "01100100", "00100111"]
>> program.bytes.map {|byte| byte.to_s(2).rjust(8,'0')}.join.to_i(2)
=> 9796543849500706521102980495717740021834791
>> number = program.bytes.map {|byte| byte.to_s(2).rjust(8,'0')}.join.to_i(2)
=> 9796543849500706521102980495717740021834791
>> number.to_s(2).scan(/.+?(?=.{8}*\z)/)
=> ["1110000", "01110101", "01110100", "01110011", "00100000", "00100111", "01101000", "01100101", "01101100", "01101100", "01101111", "00100000", "01110111", "01101111", "01110010", "01101100", "01100100", "00100111"]
>> number.to_s(2).scan(/.+?(?=.{8}*\z)/).map {|string| string.to_i(2).chr }.join
=> "puts 'hello world'"
>> program = number.to_s(2).scan(/.+?(?=.{8}*\z)/).map {|string| string.to_i(2).chr }.join
=> "puts 'hello world'"
>> eval program
hello world
=> nil
出典アンダースタンディング コンピュテーション――単純な機械から不可能なプログラムまで
著者Tom Stuart
訳者笹田 耕一
監訳笹井 崇司
出版社オライリージャパン

irb

補完

>> require "irb/completion"

プロンプト

%irb --simple-prompt
>> 

win32ole

IE

require 'win32ole'
ie = WIN32OLE.new('InternetExplorer.Application')
ie.visible = true
ie.navigate("http://www.pragprog.com")
require 'win32ole'

ie = WIN32OLE.new('InternetExplorer.Application')
ie.visible = true
ie.gohome

DLL

require 'dl/import'

module User32
  extend DL::Importer
  dlload 'user32.dll'

  extern "int MessageBoxA(long,const char*,const char *,int)"
end

MB_OKCANCEL = 1

User32.MessageBoxA(0,"OK?","Please Confirm",MB_OKCANCEL)

Windows環境

c:\>assoc .rb=RubyScript
.rb=RubyScript

c:\>ftype RubyScript="C:\ruby\bin\ruby.exe" %l %*
RubyScript="C:\ruby\bin\ruby.exe" %l %*

c:\>set PATHEXT=.rb;%PATHEXT%
環境変数にパスを追加することを忘れずに。

%記法

記法種類式展開Perlでは
%!hoge!
%Q!hoge!
文字列リテラル有効qq//
%q!hoge!文字列リテラル無効q//
%x!command!バッククォート文字列有効qx//
%r!regexp!正規表現リテラル有効m!!
%w!foo bar!配列無効qw//
%W!foo bar!配列有効?
%s!hoge!シンボル無効-

String#%

"%04d" % 5=> "0005"

コーディングスタイル

  • variable_name
  • method_name
  • ModuleName
  • ClassName
  • ConstName
  • filename

グローバル変数

require 'English'
$ERROR_INFO$!
$ERROR_POSITION$@
$FS$;
$FIELD_SEPARATOR$;
$OFS$,
$OUTPUT_FIELD_SEPARATOR$,
$RS$/
$INPUT_RECORD_SEPARATOR$/
$ORS$\
$OUTPUT_RECORD_SEPARATOR$\
$INPUT_LINE_NUMBER$.
$NR$.
$LAST_READ_LINE$_
$DEFAULT_OUTPUT$>
$DEFAULT_INPUT$<
$PID$$
$PROCESS_ID$$
$CHILD_STATUS$?
$LAST_MATCH_INFO$~
$IGNORECASE$=
$ARGV$*
$MATCH$&
$PREMATCH$`
$POSTMATCH$'
$LAST_PAREN_MATCH$+

はまった

  • require 'tk'ができなかった。->apt-get install libtcltk-ruby で解決
  • require 'mechanize'ができない
  1. apt-get install ruby1.9.1-full
  2. gem install mechanize
  3. スクリプトに以下を追加
reuire 'require 'rubygems'
gem 'mechanize'
require 'mechanize'

vim開発環境

apt-get install vim-gnome
apt-get install rubygems1.9.1
gem install vim-ruby
vim-ruby-install.rb
vi .vim/indent/ruby.vim
最終行のインデント設定を有効にする

リファレンスマニュアルインストール

http://www.ruby-lang.org/ja/man/archive/snapshot/
server.rbを自動起動する
http://localhost:10080へアクセス

refeの作成.Ruby逆引きハンドブックP72参照

追加のライブラリ

Win32ole 使い方

# -*- coding: windows-31J -*-

require 'win32ole'

module Worksheet
  def [] y,x
    cell = self.Cells.Item(y,x)
    if cell.MergeCells
      cell.MergeArea.Item(1,1).Value
    else
      cell.Value
    end
  end

  def []= y,x,value
    cell = self.Cells.Item(y,x)
    if cell.MergeCells
      cell.MergeArea.Item(1,1).Value = value
    else
      cell.Value = value
    end
  end
  def pick_range str
    self.UsedRange.Cells.each do |cell|
      if cell.Value.to_s =~ /#{str}/
        return cell
      end
      nil
    end
  end

  def right_range range
    cell = self.Cells.Item(range.Row,range.Column + 1)
    if cell.MergeCells
      cell.MergeArea.Item(1,1)
    else
      cell
    end
  end

  def up_range range
    n = (range.Row.to_i) -1 
    n = !n ? 1 : n
    cell = self.Cells.Item(n,range.Column)
    if cell.MergeCells
      cell.MergeArea.Item(1,1)
    else
      cell
    end
  end

  def left_range range
    cell = self.Cells.Item(range.Row,(range.Column.to_i) -1)
    if cell.MergeCells
      cell.MergeArea.Item(1,1)
    else
      cell
    end
  end

  def down_range range
    cell = self.Cells.Item(range.Row + 1,range.Column)
    if cell.MergeCells
      cell.MergeArea.Item(1,1)
    else
      cell
    end
  end
end

begin
  xl = WIN32OLE.new('Excel.Application')
  book = xl.Workbooks.Open("File.xls")
  begin
    sheet = book.Worksheets.Item("費用")
    sheet.extend Worksheet
    target = sheet.pick_range("ニセコいこいの村")
    up = sheet.up_range(target)
    right_range = sheet.right_range(target)
    down = sheet.down_range(target)
    left = sheet.left_range(target)

    sheet.Rows(target.Row).Insert #上に1行追加
    sheet.Rows(down.Row).Insert   #下に1行追加

    book.Save
  ensure
    book.Close
  end
ensure
  xl.Quit
end

このページへのコメント

The romantic comedy starring Zoe Kazan, which hasn't got a theatrical release, has been made available for rent at $5 on the movie's official site
Celine Trapeze Luggage Leather Bag 2013 Rose http://celinehermesbags.com/celine-trapeze-luggage-leather-bag-2013-rose-cl11505-p-31468.html

0
Posted by Celine Trapeze Luggage Leather Bag 2013 Rose 2014年04月23日(水) 07:38:13 返信

4ZHH7a Im grateful for the blog post.Thanks Again. Want more.

0
Posted by stunning seo guys 2014年01月22日(水) 07:32:21 返信

fuRZZJ Awesome article post.Much thanks again. Keep writing.

0
Posted by watch for this 2013年12月20日(金) 07:03:36 返信

Ruby - Yamanobori_old鐃緒申Memo - Seesaa Wiki鐃淑ワ申鐃緒申鐃緒申鐃緒申 for 鐃緒申鐃殉¥申鐃夙フワ申鐃緒申 ≪潟若 吾若 http://www.pslcbi.com/moncler2014.html

0
Posted by ≪潟若 吾若 2013年12月08日(日) 18:34:38 返信

KmAqAO <a href="http://pjbiyiommoha.com/">pjbiyiommoha</a>, [url=http://hxvtplwlqsmw.com/]hxvtplwlqsmw[/url], [link=http://laafqhugbpyu.com/]laafqhugbpyu[/link], http://gltfesrhgpgs.com/

0
Posted by fpfzjw 2013年11月15日(金) 02:58:30 返信

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

管理人/副管理人のみ編集できます