ユーザ用ツール

サイト用ツール


ruby:basic

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

次のリビジョン
前のリビジョン
ruby:basic [2018/06/25 09:40] – 外部編集 127.0.0.1ruby:basic [2018/07/20 14:18] (現在) taka
行 3: 行 3:
 ここでの解説はRuby 2.00を前提にしています。 ここでの解説はRuby 2.00を前提にしています。
  
-===== インストール(Mac OS X 10.7, 10.8, 10.9) =====+===== インストール(MacOS 10.7,10.8,10.9) =====
  
-  $ ./configure --prefix=/usr/local --with-opt-dir=/usr/local --enable-shared --enable-pthread +<sxh bash; gutter: false> 
-  $ make +$ ./configure --prefix=/usr/local --with-opt-dir=/usr/local --enable-shared --enable-pthread 
-  $ sudo make install+$ make 
 +$ sudo make install 
 +</sxh>
  
 Mac OSの一部ではrubyのインストールは正常終了してもgemを使う時に以下のようなエラーが発生する。 Mac OSの一部ではrubyのインストールは正常終了してもgemを使う時に以下のようなエラーが発生する。
  
-  $ gem install json +<sxh bash; gutter: false> 
-  ERROR:  Loading command: install (LoadError) +$ gem install json 
-      cannot load such file -- openssl +ERROR:  Loading command: install (LoadError) 
-  ERROR:  While executing gem ... (NoMethodError) +    cannot load such file -- openssl 
-      undefined method `invoke_with_build_args' for nil:NilClass+ERROR:  While executing gem ... (NoMethodError) 
 +    undefined method `invoke_with_build_args' for nil:NilClass 
 +</sxh>
  
 これはOpenSSLのバージョンが古いことに起因しているらしいので、まず最新のOpenSSLをインストールする。 これはOpenSSLのバージョンが古いことに起因しているらしいので、まず最新のOpenSSLをインストールする。
行 21: 行 25:
   * [[https://www.openssl.org/source/openssl-1.0.2d.tar.gz|openssl-1.0.2d.tar.gz]]   * [[https://www.openssl.org/source/openssl-1.0.2d.tar.gz|openssl-1.0.2d.tar.gz]]
  
-  $ ./configure darwin64-x86_64-cc --prefix=/usr/local --openssldir=/usr/local/openssl +<sxh bash; gutter: false> 
-  $ make +$ ./configure darwin64-x86_64-cc --prefix=/usr/local --openssldir=/usr/local/openssl 
-  $ sudo make install+$ make 
 +$ sudo make install 
 +</sxh>
  
 その後、--with-opt-dir=/usr/localオプションを使用してRubyを再度インストール。 その後、--with-opt-dir=/usr/localオプションを使用してRubyを再度インストール。
 +
 +<sxh bash; gutter: false>
   $ ./configure --prefix=/usr/local --with-opt-dir=/usr/local --enable-shared --enable-pthread   $ ./configure --prefix=/usr/local --with-opt-dir=/usr/local --enable-shared --enable-pthread
   $ make   $ make
   $ sudo make install   $ sudo make install
 +</sxh>
  
-===== インストール(Mac OS X 10.5, 10.6) =====+===== インストール(MacOS 10.5,10.6) =====
  
-  $ ./configure --prefix=/usr/local --enable-shared --enable-pthread +<sxh bash; gutter: false> 
-  $ make +$ ./configure --prefix=/usr/local --enable-shared --enable-pthread 
-  $ sudo make install+$ make 
 +$ sudo make install 
 +</sxh>
  
 gem実行時に以下のエラーが出た場合は、LibYAMLをインストールして環境変数を設定した後、Rubyを再度インストールすることで解決する。 gem実行時に以下のエラーが出た場合は、LibYAMLをインストールして環境変数を設定した後、Rubyを再度インストールすることで解決する。
行 43: 行 54:
   * **[[http://pyyaml.org/wiki/LibYAML|LibYAML]]**   * **[[http://pyyaml.org/wiki/LibYAML|LibYAML]]**
  
-  $ ./configure +<sxh bash; gutter: false> 
-  $ make +$ ./configure 
-  $ sudo make install+$ make 
 +$ sudo make install 
 +</sxh>
  
 環境変数に以下を加える。 環境変数に以下を加える。
行 61: 行 74:
 Windowsの環境変数「PATH」に以下を追加。 Windowsの環境変数「PATH」に以下を追加。
  
-<sxh plain; gutter: false;> +  C:\usr\bin;C:\usr\lib;C:\usr\include;C:\DevKit\bin;C:\DevKit\lib;C:\DevKit\include;C:\DevKit\mingw\bin;C:\DevKit\mingw\lib;C:\DevKit\mingw\include
-C:\usr\bin;C:\usr\lib;C:\usr\include;C:\DevKit\bin;C:\DevKit\lib;C:\DevKit\include;C:\DevKit\mingw\bin;C:\DevKit\mingw\lib;C:\DevKit\mingw\include +
-</sxh>+
  
 DevKitの設定 DevKitの設定
  
-  $ cd C:/DevKit +<sxh bash; gutter: false> 
-  $ ruby dk.rb init+$ cd C:/DevKit 
 +$ ruby dk.rb init 
 +</sxh>
  
 C:/DevKit/config.ymlができるので以下のように編集。 C:/DevKit/config.ymlができるので以下のように編集。
  
-<sxh plain; gutter: false;>+<sxh bash; gutter: false>
 # This configuration file contains the absolute path locations of all # This configuration file contains the absolute path locations of all
 # installed Rubies to be enhanced to work with the DevKit. This config # installed Rubies to be enhanced to work with the DevKit. This config
行 92: 行 105:
 以下コマンドを実行して反映。 以下コマンドを実行して反映。
  
-  $ ruby dk.rb install+<sxh bash; gutter: false> 
 +$ ruby dk.rb install 
 +</sxh>
  
 Gemでriとrdocをインストールしないように設定。\\  Gemでriとrdocをインストールしないように設定。\\ 
 C:/Users/<username>/.gemrc を作成して以下を追加。 C:/Users/<username>/.gemrc を作成して以下を追加。
  
-<sxh plain; gutter: false;> +  gem: --no-ri --no-rdoc
-gem: --no-ri --no-rdoc +
-</sxh> +
- +
-  gem update --system+
  
 ===== ソースファイルの文字コードを指定する ===== ===== ソースファイルの文字コードを指定する =====
  
-<sxh ruby; gutter: false;>+<sxh ruby>
 #!/usr/bin/ruby #!/usr/bin/ruby
 # coding: utf-8 # coding: utf-8
行 114: 行 125:
 ==== ファイル入出力時の文字コードを指定する ==== ==== ファイル入出力時の文字コードを指定する ====
  
-<sxh ruby; gutter: false;>+<sxh ruby>
 #!/usr/bin/ruby #!/usr/bin/ruby
 # coding: utf-8 # coding: utf-8
行 131: 行 142:
 ==== 多階層ディレクトリの作成方法 ==== ==== 多階層ディレクトリの作成方法 ====
  
-<sxh ruby; gutter: false;>+<sxh ruby>
 #!/usr/bin/ruby #!/usr/bin/ruby
 # coding: utf-8 # coding: utf-8
行 149: 行 160:
 === オプション使用例 === === オプション使用例 ===
  
-<sxh ruby; gutter: false;>+<sxh ruby>
 # ディレクトリ作成時のパーミッションを指定通りにするため予めumaskに0を設定 # ディレクトリ作成時のパーミッションを指定通りにするため予めumaskに0を設定
 File.umask(0) File.umask(0)
行 157: 行 168:
 ===== トランスコーディング ===== ===== トランスコーディング =====
  
-<sxh ruby; gutter: false;>+<sxh ruby>
 #!/usr/bin/ruby #!/usr/bin/ruby
 # coding: utf-8 # coding: utf-8
行 175: 行 186:
 </color> </color>
  
-<sxh ruby; gutter: false;>+<sxh ruby>
 #!/usr/bin/ruby #!/usr/bin/ruby
 # coding: utf-8 # coding: utf-8
行 192: 行 203:
 ==== アクセサメソッド ==== ==== アクセサメソッド ====
  
-<sxh ruby; gutter: false;>+<sxh ruby>
 # ゲッターメソッドを生成 # ゲッターメソッドを生成
 attr_reader   :name attr_reader   :name
行 201: 行 212:
 </sxh> </sxh>
  
-<sxh ruby; gutter: false;>+<sxh ruby>
 # ------------------------------------------------------ # ------------------------------------------------------
 class Test class Test
 # ------------------------------------------------------ # ------------------------------------------------------
   
- attr_reader   :name1 +  attr_reader   :name1 
- attr_writer   :name2 +  attr_writer   :name2 
- attr_accessor :name3+  attr_accessor :name3
   
- # -------------------------------------------------- +  # -------------------------------------------------- 
- def initialize(name1,name2,name3) +  def initialize(name1,name2,name3) 
- # -------------------------------------------------- +  # -------------------------------------------------- 
- @name1 = name1 +    @name1 = name1 
- @name2 = name2 +    @name2 = name2 
- @name3 = name3 +    @name3 = name3 
- end+  end
 end end
  
行 229: 行 240:
 test.name3 = "NewName3" # OK test.name3 = "NewName3" # OK
 puts test.name3         # -> NewName3 puts test.name3         # -> NewName3
- 
 </sxh> </sxh>
  
  
ruby/basic.1529887234.txt.gz · 最終更新: 2018/06/25 09:40 by 127.0.0.1