Ruby

Articles on 11 May 2014 - Earth view from ISS and Pry(Ruby interpreter)

USTREAM: ISS HD Earth Viewing Experiment: ***QUICK NOTES ABOUT HDEV VIDEO*** Black Image = International Space Station (ISS) is on the night side of the Ea... This is a live stream of the earth from ISS, International Space Station. You ca…

RSpec basics

Recently I have re-studied the RSpec. This is just my reminder. describe to be used to group something to be described. can be nested. context same as describe but usually used to list some different conditions it to be used to write test …

Rubyにおけるインスタンス変数 クラス変数 クラスインスタンス変数(Instance variables, class variables and class instance variables in ruby)

(English follows)Rubyにおけるインスタンス変数 クラス変数 クラスインスタンス変数に関するメモ。以下の記事に対するコメントを含んでいる。includeとextendの違いについて - shoutm's diary結論は以下の通り。 インスタンス変数はオブジェクトに属する ク…

Reijiro - An English learning tool

I've found a sleek open source software for English study.Reijiro: 間隔反復学習で英辞郎を「読む」アプリ knsmr/reijiro · GitHubHave you heard of "Spaced repetition"? According to wikipedia: Spaced repetition is a learning technique that inc…

Useful method "random.choice"

In case of choosing an element in a list randomly, I usually write a code like below.Ruby: ary = [1, 2, 3, 4, 5] print ary[rand(0...ary.length)] But in python, an useful method exists. import random ary = [1, 2, 3, 4, 5] print(random.choic…

The Idea of "class" in python

I have studied Python recently and I found little differences between python and other programming languages.class definition: class Person(SuperClass, SuperClass2): # multiple inheritance is possible i = 1 # class variable # constructor d…

大域脱出(ruby, java)

rubyには大域脱出という機能があることを思い出したのでメモ。 通常のbreakだと複数のループからは抜けられないが、大域脱出を使えば任意のラベルの箇所まで脱出が可能。goto文がない言語だと大域脱出 or 例外処理を使う必要がある。 以下rubyの例。 puts "=…

モジュール変数について

モジュールの内部でクラス変数のようなモジュール変数を定義できるらしい。 require "active_support/all" module Test mattr_accessor :var @@var = 1 end Test.var #=> 1 Test::var #=> 1 ちなみにmattr_accessorを使うにはrequire "active_support/all"し…

includeとextendの違いについて

ふとActionController::TestCaseを読んでいたときに以下のような書き方を見つけた。 class TestCase < ActiveSupport::TestCase module Behavior extend ActiveSupport::Concern include ActionDispatch::TestProcess : 勉強不足だ。。とりあえず調べてみる…