Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 1 year has passed since last update.

d2_ruby: six things

Last updated at Posted at 2023-09-27

my_help

  1. Ruby言語で自作のgem, my_gemを作る方法を教えてください.
  2. gem環境構築にbundlerを使った場合の例を教えてください.
  3. bundlerのgem雛形作成機能を使った場合はどうなりますか?

my_help

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
print puts, p
variable ARGV snake_case vs CamelCase
array, hash
loop enumerate each
if case, ternary
method class

six things

print

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
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?