Ruby — Паттерны программирования

  • Published on
    14-Jun-2015

  • View
    1.715

  • Download
    0

Embed Size (px)

DESCRIPTION

ruby ( ).

Transcript

  • 1. 2 3 References 10-11 24 2012 . 10-11

2. 2 3 References . :1 .2 .3 , .4 , ?5 . 10-11 3. 2 3 References 1 10-11 4. 2 3 References - . , : . , max, . . - , , . max. 10-11 5. 2 3 References 1 1 . 2 max . 3 max, max. 4 , : max? 5 max = 0, , . 10-11 6. 2 3 References 1 , . - . 10-11 7. 2 3 References 1 : , ( ). , .Listing 1: 1 d e f max ( a r r a y ) r e t u r n f a l s e i f a r r a y . empty ?max = a r r a y [ 0 ] f o r i i n 0 . . a r r a y . s i z e 1 max = a r r a y [ i ] i f ( a r r a y [ i ] > max )endmax end 10-11 8. 2 3 References 1 , array.size. , , . . , ? ! ! , : array.size-1. 1? ruby . , n , n 1. 10-11 9. 2 3 References 1Listing 2: 1 d e f max ( a r r a y ) r e t u r n f a l s e i f a r r a y . empty ?max = a r r a y [ 0 ] s i z e = a r r a y . s i z e 1 for i in 0 . . s i z e max = a r r a y [ i ] i f ( a r r a y [ i ] > max )endmax end 10-11 10. 2 3 References 2 . 10-11 11. 2 3 References - . : . max , , . , , . : . max_key max_value. 10-11 12. 2 3 References 1 : , , array[i], i. : , . . , , , . 10-11 13. 2 3 References 2Listing 3: 2 d e f max ( a r r a y ) r e t u r n f a l s e i f a r r a y . empty ?max_key= 0max_value = a r r a y [ 0 ] s i z e = a r r a y . s i z e 1 for i in 0 . . s i z ei f ( a r r a y [ i ] > max ) max_key = i max_value = a r r a y [ i ] endend [ max_key , max_value ] end 10-11 14. 2 3 References 3 . 10-11 15. 2 3References , , . , : nd_all elem. : . , , . has_negative ag ( , , . Listing 4: 3 p u t s "" i f a r r a y . f i n d _ a l l { | e l e m | elem

Recommended

View more >