ラベル ruby の投稿を表示しています。 すべての投稿を表示
ラベル ruby の投稿を表示しています。 すべての投稿を表示

2020/10/17

fatal error: 'libpq-fe.h' file not found

 libpq-fe.h が見当たらないらしい。

次のコマンドで postgresql をインストールすることで解決。

libpqはpostgresqlのことだね

brew install postgresql

2020/10/13

rbenv nodenv

// 1.初期化設定
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
// 2.初期化設定の反映(既存のRubyはこれで無視される)
$ source ~/.bash_profile
// 3.rbenvのインストール:
$ brew install rbenv ruby-build
// 4.インストール可能なRubyのバージョン一覧の表示
$ rbenv install -l
// 5.指定したRubyのバージョンをインストール
$ rbenv install 2.3.5
// 6.インストールしたRubyを使用可能な状態にする⇒shimsへの反映
$ rbenv rehash


全く同じ手順で nodenvをインストールできる

2019/09/25

docker-sync ruby error

xcodeアップデートしますかを聞かれて、アップデートした。
docker-syncがエラー

docker-sync start
mkmf.rb can't find header files 

ruby versionの管理が混乱になっている。
rbenvを導入

 brew update
 brew install rbenv ruby-build
rbenv install -l
rbenv install 2.6.4
エラー、BUILD FAILED (OS X 10.。。。。
sudo chmod -s /usr/sbin/dtrace
RUBY_CONFIGURE_OPTS="--disable-dtrace" rbenv install
でrubyをインストールできた。
which gem
which ruby
gem list
gem install docker-compose
gem install docker-sync
でOK

2014/10/24

ruby `require': no such file to load -- mysql (LoadError)

require 'mysql'
でエラーになった
でも
sudo gem install ruby-mysqlをインストール済みが。。
先に
require 'rubygems'
が必要だ。。

で、sudo ruby
=>sudo: ruby: コマンドが見つかりません
which ruby
==>/usr/local/bin

で、visodu
visudoでsecure_pathに「/usr/local/bin」を追加する。

2014/10/03

ruby require エラー

Rubyファイルを実行するとrequireでエラーがでてるよってとき

require "kakiku"
==>エラーになり、書き方を修正する
require File.expand_path('kakiku.rb',__FILE__)=>NG
require File.expand_path('./kakiku.rb',__FILE__)=>NG
require File.expand_path('../kakiku.rb',__FILE__)=>OK

バージョン:
ruby 2.0.0p353 (2013-11-22) [x86_64-linux]

2014/08/18

ruby on rails

bundle install
==>Install the modules include in the gemfile.
Unless you specify a version number to the gem command, Bundler will automatically install the latest version of the gem.
bundle update===>update!!


・deployの準備
bundle install --without production
group :production do
    gem 'pg'
    gem 'rails_12factor'
end

・@なになに。。
Once the @users variable is defined, the controller calls the view (Step 6), shown in Listing 2.6. Variables that start with the @ sign, called instance variables, are automatically available in the view;

・rails new sample_app --skip-test-unit
===>not to create test directory

・rails generate controller StaticPages home help --no-test-framework
===>「home help」MVCセットで2つ作る

・rails generate rspec:install
bundle exec rspec spec/requests/..rb==>実行、red->green->refactor

・JetBrains:
==>alt+ctr+s =->editerのところでline番号を表示する。

・<% provide(:title, 'Home') %>
Rails should call the provide function and associate the string ’Home’ with the label :title.
<%= yield(:title) %>
    yield==->自分で定義したブロック付きメソッドでブロックを呼び出すときに使います

・application.html.erb:
<%= yield %>
==>This code is responsible for inserting the contents of each page into the layout. It’s not important to know exactly how this works; what matters is that using this layout ensures that, for example, visiting the page /static_pages/home converts the contents of home.html.erb to HTML and then inserts it in place of <%= yield %>.


・first_name + " " + last_name
===
"#{first_name} #{last_name}"

・# Single-quoted strings don't allow interpolation

・Note that Ruby functions have an implicit return
meaning they return the last statement evaluated

・a = [42, 8, 17]
a[-1]==>17
a.sort
a.sort!===>a!
a.push(6)
a << 7
a << "foo" << "bar"

a.split--->array になる
array.join-->stringになる


(0..9).to_a
a[0..2]


・|i|
==>The vertical bars around the variable name in |i| are Ruby syntax for a block variable

2014/07/15

Ruby On Rails

・ruby をインストールする
==>環境変数に追加する
・DevKit
ーー>downloadして解凍し、インストールする
ruby dk.rb init
==>rubyのディレクトリをconfi.ymlにincludeする
ruby dk.rb install

gem update --system
gem update rake
gem install rails

エラー==>x86_64-w64-mingw32-gcc command not found
    ==>devkitのバージョンが間違った!!


rails new blog
==>project作成

bundle install
==ー>projectを配置する

rake db:create
=->dbを作成する、sqlite is default

rails server
==>serverを起動する

=->地雷:no source of timezone data
----------
Try changing the tzinfo-data line in your Gemfile to gem 'tzinfo-data', platforms: [:x64_mingw, :mingw, :mswin] and then running bundle update.

The :x64_mingw platform option is needed to match 64-bit Windows MinGW builds of Ruby (such as the RubyInstaller x64 builds).
bundel update
---------

rails g controller home index
rails g scaffold post name:string title:string content:text
=>postのapp Templateみたいな物!



class Post < AcitveRecond :: Base
end

==>AcitveRecond :: Baseを継承しているから、CRUD、validate、などすごい機能があります。

==>何となくPLAY Frameworkに似っている!!。同じスタイル!

rails g model comment commenter:string body:text post:references

rake db:migrate===>dbを更新する,modle更新の後で。。

2013/08/29

ruby xml操作 REXML

ーファイルーー
<root>
    <a name="a1">
        <b>bbb1</b>
        <b>bbb2</b>
        <b>bbb3</b>
        <c>ccc1</c>
    </a>
    <a>
        <b>bbb4</b>
        <b>bbb5</b>
    </a>
    <a name="a3" price="100"></a>
</root>



puts doc.elements['root/a/b'].text
=>bbb1



puts doc.elements['root/a[2]/b[2]'].text
=>bbb5



doc.elements.each('root/a/b') do |element|
  puts element.text
end
=>bbb1~bbb5



doc.elements.each('root/a[1]/b[2]') do |element|
  puts element.previous_element.text
end
=>bbb1



doc.elements.each('root/a[1]/b[2]') do |element|
  puts element.next_element.text
end
=>bbb3



doc.elements.each('root/a[1]') do |element|
  puts element.name
end
=>a



doc.elements.each('root/a[2]') do |element|
  puts element.elements.size
end
=>2



doc.elements.each('root/a[3]') do |element|
  puts element.attributes["name"]
end
=>a3



hash = Hash.new
doc.elements.each('root/a[3]') do |element|
  hash = element.attributes
end
puts hash.size     #=>2
puts hash["name"]  #=>a3



doc.elements.each("root/a[@name='a1']/b") do |element|
  puts element.text
end
=>bbb1
bbb2
bbb3



puts doc.elements["root/a[@name='a3']"].attributes['price']
=>100



更新する
doc = Document.new File.new("guitars.xml")
elements["color"].text = "Red"
File.write("guitars.xml",doc)
rubyの古いバージョンで上記はエラーになった。
open(path, "w") {|f| f.write doc}

2013/06/20

phython ruby メリット

何のために作ったのか?
何のメリットがある?
=>簡単で、他のソフト(ライブラリー)を使えになる(呼び出し)こと?
それは次のIT世代のあり方でもある。
=>読みやすい、書きやすい、自然言語に近い

ruby:
・インタプリタ
Rubyはインタプリタ言語ですので プログラムを実行するためにコンパイルする必要ない

・ユーザのメモリ管理が不要
Rubyはメモリ管理を自動的に行う。 どこからもアクセスされなくなったオブジェクトはインタプリタに組み込みのガーベージコレクタによって回収される
・Mix-in
多重継承は複雑さの源であるという見地から、 意図的に多重継承を持たなく、
モジュールを使ってクラス階層を横断して実装を共有し、この機能を"Mix-in"と呼ぶ

・OSへの直接アクセス
Rubyは(UNIXの)ほとんどのシステムコールの呼び出し機能を持つ、 Rubyだけでシステムプログラミングも可能。