Thuta Learning
ရှာဖွေရန်
BasicProgrammingbeginner

Data Types

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Ruby data type တွေကို နားလည်ထားရင် method သုံးတာ၊ condition စစ်တာ၊ collection တွေကို ကိုင်တာ ပိုလွယ်ပါတယ်။ Ruby မှာ အသုံးများတာတွေက String, Integer, Float, Boolean, Nil, Array, Hash တို့ပါ။

ruby
name = "Ruby"       # String
age = 25           # Integer
price = 10.99      # Float
is_fun = true      # TrueClass
nothing = nil      # NilClass

puts name.class
puts age.class
puts price.class
puts nothing.nil?

.class က object ရဲ့ class/type ကိုပြပါတယ်။ nil? က value က nil ဖြစ်/မဖြစ် true/false ပြန်ပေးပါတယ်။

You should see
String Integer Float true

Info

nil သည် တန်ဖိုးမရှိခြင်းကို ဆိုလိုပါတယ်။ Empty string "" နဲ့ မတူပါ။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • nil ကို string "nil" နဲ့မရောပါနဲ့။ nil က value မရှိတာ၊ "nil" က စာသားပါ။
Data Types | Thuta Learning