Last active
August 29, 2015 14:01
-
-
Save muratatak77/1d60b204dff45bc01ef0 to your computer and use it in GitHub Desktop.
Assgnmt - 4 (Random , Hash , Map , Regex Email Check , self method calling)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. 'e' ve 'x' arasindaki harflerden 7 haneli random string ureten bir fonksiyon yaziniz | |
2.1.1 :123 > (0...7).map { ('e'..'x').to_a[rand(20)] }.join | |
=> "tjtwnpg" | |
2. Verilen string'in gecerli mail adresi oldugunu denetleyen bir fonksiyon yaziniz. (Ipucu: Regex) | |
2.1.1 :365 > def is_a_valid_email?(email) | |
2.1.1 :366?> | |
2.1.1 :367 > email_regex = %r{ | |
2.1.1 :368/> ^ # Start of string | |
2.1.1 :369/> | |
2.1.1 :370/> [0-9a-z] # First character | |
2.1.1 :371/> [0-9a-z.+]+ # Middle characters | |
2.1.1 :372/> [0-9a-z] # Last character | |
2.1.1 :373/> | |
2.1.1 :374/> @ # Separating @ character | |
2.1.1 :375/> | |
2.1.1 :376/> [0-9a-z] # Domain name begin | |
2.1.1 :377/> [0-9a-z.-]+ # Domain name middle | |
2.1.1 :378/> [0-9a-z] # Domain name end | |
2.1.1 :379/> | |
2.1.1 :380/> $ # End of string | |
2.1.1 :381/> }xi # Case insensitive | |
2.1.1 :382?> | |
2.1.1 :383 > if (email =~ email_regex) | |
2.1.1 :384?> puts "gecerli" | |
2.1.1 :385?> else | |
2.1.1 :386 > puts "gecersiz" | |
2.1.1 :387?> end | |
2.1.1 :388?> | |
2.1.1 :389 > | |
2.1.1 :390 > end | |
=> :is_a_valid_email? | |
2.1.1 :391 > | |
2.1.1 :392 > is_a_valid_email?("musfsdjf") | |
gecersiz | |
=> nil | |
2.1.1 :393 > is_a_valid_email?("murat@murat.coo") | |
gecerli | |
=> nil | |
2.1.1 :394 > is_a_valid_email?("murat@murat.com") | |
gecerli | |
=> nil | |
2.1.1 :395 > | |
3. Video diye bir sinif olusturunuz. | |
@video.transcode! Deyince 'transcode basladi' yazdirsin | |
class Video | |
def @self.transcode!() | |
puts "transcode basladi" | |
end | |
end | |
muratatak@muratatak ~ $ irb | |
2.1.1 :001 > require '/home/muratatak/Documents/ror/assg4/video' | |
=> true | |
2.1.1 :002 > @video.transcode! | |
transcode basladi | |
=> nil | |
2.1.1 :003 > | |
4. Preset diye bir sinif olusturun. | |
Preset.high_definition deyince 'hd ayatlari' yazdirsin | |
class Preset | |
def self.high_definition | |
puts "hd ayatlari" | |
end | |
end | |
muratatak@muratatak ~ $ irb | |
2.1.1 :001 > require '/home/muratatak/Documents/ror/assg4/preset' | |
=> true | |
2.1.1 :002 > Preset.high_definition | |
hd ayatlari | |
=> nil | |
2.1.1 :003 > | |
5. Ruby'nin File sinifini inceleyiniz. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment