LoginSignup
0
0

More than 3 years have passed since last update.

プログラミングは神になれる。

Posted at

プログラミングの楽しさについて書きます。

それはオブジェクト思考がまるで生き物を作る神になった気分になれるところです。

そのコードの例が下記になります。

class Human
  @name
  @age
  @wanryoku

  def walk
  end

  def eat
  end

  def age= num
    if num < 0
      puts 
      @age = 0
      return 
    end
    @age = num

  end

end

class SuperMan < Human
  def me_kara_beam
  end
end


human = Human.new
human.walk #ok
human.me_kara_beam #error
spMan = SuperMan.new
spMan.walk #ok
spMan.me_kara_beam #ok

これは、ヒューマンは歩くことができるが、目からビームが出せない
スーパーマン(spMan)は歩くこと、目からビームを出すことができる
という処理です。

一見難しそうに見えるプログラミングも、こうみると面白いのかなとおもったり。

日々の学習をドキュメントに残してるので、とっても暇な時みてみてください。
https://www.notion.so/Ruby-Ruby-on-Rails-84f5c88189474fa4aae5e00cba856226

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