my_help
- Ruby言語で自作のgem, my_gemを作る方法を教えてください.
- gem環境構築にbundlerを使った場合の例を教えてください.
- bundlerのgem雛形作成機能を使った場合はどうなりますか?
my_help
- shell(zsh, fish, bash) : pwd, ls
- my_help : gem install my_help(https://github.com/daddygongon/my_help .git?)
emacsの基本ショートカット
- C-f, move Forwrard, 前or右へ
- C-b, move Backwrard, 後or左へ
- C-a, go Ahead of line, 行頭へ
- C-e, go End of line, 行末へ
- C-n, move Next line, 次行へ
- C-p, move Previous line, 前行
- C-d, delete
- C-k, kill line
- C-x C-s, save file
- C-z, 一時中断 -> fg (fore ground)
- C-x C-c, 完全終了
programmingの基本要素(Ruby)
- interpreter ruby : irb
- emacs test.rb
- ruby test.rb
name | Ruby | comment |
---|---|---|
puts, p | ||
variable | ARGV | snake_case vs CamelCase |
array, | hash | |
loop | enumerate | each |
if | case, ternary | |
method | class |
six things
print("print hello\n")
printf("printf hello\n")
puts("puts hello")
puts "puts hello"
p "p hello" # programの途中経過を見るときに,変数全てを表示
puts "hello %s." % "bob"
printf "hello %s.\n", "bob"
variable
name = "bob"
p 'single quatation: hello #{name}.'
p "double quatation: hello #{name}."
p name2 = "hello " + name
p name2 = "hello " + 1.to_s
p '1'
p '1'.to_i
p variable = 1.1
array
p data = [1, 2, 3]
p data = ['1', 2, 3]
p data[0]
p data << 4
p data.delete_at(0)
p data
#hash , dictionary on Python
p data = {'one'=> 1, 'two' => 2}
p data['one']
p data['two']
p data = {:one => 1, :two => 2}
p data[:one]
p data[:two]
p :two.to_s
p 'two'.to_sym
p data = {one: 1, two: 2}
p data[:one]
p data[:two]
data[:three]=3
p data
loop
# Enumelater
# each
['one', 'two', 'three'].each_with_index do |char, i|
p [i, char]
if i==2
next
end
end
exit
4.times do |i|
p i+1
end
for i in 1..3 do
p i
end
i = 0
while i< 5 do
p i
i += 1
end
if
a = 3
puts case a
when 1,2
'hello'
when 3
'hello2'
else
'hello other'
end
exit
# Enumelater
# each
['one', 'two', 'three'].each_with_index do |char, i|
next if i==1
p [i, char]
end
exit
a = false
b = true
if a
print a
elsif b
print b
else
print 'hello'
end
p result = a ? a : 'hello'
#if a
if a
print a
else
print 'hello'
end
a =2
if a==1
print a
else
print 'hello'
end
method
def main
name = ARGV[0] # argument vector
greeting(name)
end
def greeting(name='world')
puts "Hello #{name}."
end
=begin
p $0
# p __FILE__
p ARGV
=end
main()
my_hello_class
#!/usr/bin/env ruby
class Greeting
def initialize
name = ARGV[0] # argument vector
greeting(name)
end
def greeting(name='world')
puts "Hello #{name}."
end
end
=begin
p $0
# p __FILE__
p ARGV
=end
Greeting.new
- source ~/Desktop/lecture_23f/multi_scale_23/d2_ruby/d2_ruby.org