LoginSignup
1
1

More than 5 years have passed since last update.

Ruby で Hello World!

Posted at

概要

この記事は螺旋祭り Advent Calendar 2016の22日目の記事です。

そして、記念すべきQiita初投稿です。
何を書くか迷いましたが、最近始めたRubyで、慣習に従い"Hello World!"を出力します。

環境

  • Microsoft Azure Virtual Machines上に構築したWindows Server2012
  • ruby 2.3.1

インストール

こちらを参考にRubyInstallerでインストールしてみました。
特に問題がなかったので詳細はすっ飛ばします。

Hello World!

helloworld.rb
puts 'Hello World!'

これで"Hello World!"を出力できるのですが、あんまりなので動かします。1

stream_helloworld.rb
target = 'Hello World!'

def interval(len)
  ' ' * len
end

def init_queue(size)
  (' ' * size).split('')
end

words = target + interval(10)
queue = init_queue(30)

while true
  words.each_char do |c|
    queue.shift
    queue.push(c)
    print queue.join + "\r"
    sleep(0.1)
  end
end

実行

GIF.gif

まとめ

Rubyって書いてて楽しい♪


  1. Rubyっぽくないとか、こう書いた方がイイとかありましたら教えてください(優しく) 

1
1
3

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
1
1