Ruby, girkawa da haɓaka misali na asali a cikin Ubuntu

game da yaƙutu

A cikin labarin na gaba zamuyi la'akari da yadda zamu girka Ruby akan Ubuntu. Wannan yaren budewa, mai kuzari, daidaitaccen abu da daidaitaccen yare wanda aka bunkasa ta Yukihiro 'Matz' Matsumoto a Japan. Ana aiwatar da shi ta hanyar haɗa sifofin sauran shahararrun yarukan shirye-shirye, kamar su PERL, Smalltalk, Ada, da sauransu.

Wannan yare ne na shirye-shirye wanda aka tsara shi don sauƙaƙa wasu ayyukan cikin tsarawa. Ya rage wasu daga cikin hadaddun sassan shirye-shirye kuma ya sa ya yiwu ga mai tsara shirye-shiryen da sauri ya gina wani abu daga karce. Shin an tsara shi da farko don mutanen da suke son fara shirye-shirye, amma kowa na iya amfani da wannan yaren don ƙirƙirar hadaddun aikace-aikace.

Zamu iya girka Ruby akan Gnu / Linux ta hanyoyi da dama. Yi amfani da mai sarrafa kunshin dacewa shine hanya mafi sauki don shigar Ruby a cikin Ubuntu. A cikin wannan sakon zamu ga yadda za mu girka Ruby daga layin umarni kuma mu aiwatar da lambar misali ta asali da za mu samar da wannan yaren.

Sanya Ruby

Da farko zamu bude tashar (Ctrl + Alt + T) a cikin Ubuntu. A wannan yanayin Ina amfani da shi Ubuntu 18.04, amma za mu iya shigar da shi a cikin nau'i daban-daban na wannan rarrabawar. Kafin gudanar da umarnin don shigar da Ruby, dole ne mu Sabunta jerin kayan aikin komputa. Idan bai sabunta ba, bazai yuwu ya girka daidai ba. Don sabunta jerin, za mu aiwatar da umarni mai zuwa:

sudo apt update

Da zarar sabuntawa na tushen kayan aikin software ya ƙare, za mu aiwatar da umarni mai zuwa tare da izinin tushen zuwa shigar da jan yaƙutu:

sudo apt install ruby-full

Dole ne mu danna 'Y' idan ya nemi izini don kammala aikin shigarwa.

ruby-full shigarwa

Idan an gama shigarwa cikin nasara, zamu iya duba cewa Ruby yayi aiki daidai ko ba ta hanyar bin umarnin nan mai zuwa ba. Idan komai yayi daidai, tsarin zai nuna mana sigar ruby ​​wanda aka girka akan tsarin. Sakamakon da yake nunawa shine an sanya sigar 2.5.1 akan tsarin da nake amfani da shi don wannan misalin:

ruby version

ruby -v

Irƙiri samfurin shirin tare da Ruby

Za mu iya yi amfani da kowane editan rubutu don rubuta rubutun misali ta amfani da Ruby. A wannan yanayin zan yi amfani da editan nano. Dole ne mu yi amfani da fayil ɗin da za mu samar da shi tsawo .rb. Don wannan misali zan ƙirƙiri fayil da ake kira hi.rb. Sanin haka, muna aiwatar da wannan umarni daga tashar (Ctrl + Alt T) don buɗe edita:

nano hola.rb

A cikin wannan rubutun zamu ga sauƙin shigar da kayan aiki. Umurnin Ana amfani da samun cikin ruby ​​don karɓar bayanan mai amfani da umarni Ana amfani da sanya a cikin wannan yaren don bugawa zuwa na'urar wasan bidiyo. A Ruby, ana amfani da + mai aiki don haɗa darajar kirtani.

Don aiwatar da wannan misalin, za mu kwafa lambar ta gaba a cikin edita. Mun adana abubuwan cikin fayil ta latsa Ctrl + O da kuma latsa Shigar. Za mu gama ta latsa Ctrl + X don fita daga fayil ɗin.

misali fayil hello.rb

puts "Escribe tu nombre :"
name = gets.chomp
puts "Hola "+ name +", gracias por probar este tutorial publicado en Ubunlog.com"

Gudanar da shirinmu na samfurin

misali tare da ruby ​​aiki

Don ƙaddamar da wannan misalin, dole ne mu rubuta umarnin mai zuwa daga tashar da sauransu gudanar da sabon fayil ɗin da aka kirkira. Idan rubutun babu kurakurai, zai fara buga sakon 'Shigar da sunanka'. A can za mu rubuta wani abu kuma danna Shigar. Na gaba, zai buga saƙon da muka adana a cikin “sunan” mai canji. Za a yi wannan bugawa tsakanin zaren rubutu waɗanda an riga an bayyana su a cikin fayil ɗin da aka ƙirƙira. Don aiwatar da fayil ɗin, a cikin m (Ctrl + Alt T) mun rubuta:

ruby hola.rb

Kamar yadda kuke gani, duk da kasancewa mai sauƙin misali, idan kun kasance sababbi ga shirye-shirye, zaku iya zaɓar yaren Ruby a matsayin ɗayan zaɓinku na farko don farawa a duniyar shirye-shirye. Kodayake don farawa daga farawa, watakila mafi kyawun zaɓi shine Python. Ta bin wannan labarin mai sauƙi, kowa zai iya sauƙin shigar Ruby akan tsarin Ubuntu ɗin sa kuma fara ƙirƙirar da sauri.

Idan kowa yaso sani game da wannan harshe, zaka iya shiga ta cikin aikin yanar gizo kuma bincika halayensa ko Takardun ana iya samun hakan a can.


Bar tsokaci

Your email address ba za a buga. Bukata filayen suna alama da *

*

*

  1. Wanda ke da alhakin bayanan: Miguel Ángel Gatón
  2. Manufar bayanan: Sarrafa SPAM, sarrafa sharhi.
  3. Halacci: Yarda da yarda
  4. Sadarwar bayanan: Ba za a sanar da wasu bayanan ga wasu kamfanoni ba sai ta hanyar wajibcin doka.
  5. Ajiye bayanai: Bayanin yanar gizo wanda Occentus Networks (EU) suka dauki nauyi
  6. Hakkoki: A kowane lokaci zaka iyakance, dawo da share bayanan ka.