SlideShare ist ein Scribd-Unternehmen logo
1 von 21
4장. 문자열
 ----------------------------------------------------------------
 변수값 출력할때, #{a} 이렇게 #{} 사이에 변수명을 넣
    어주면 된다.
   x**y 는 x의 y승을 말함.
   ----------------------------------------------------------------
   puts "a #{"값#{
   # 주석
   "은 #{a}"}"}"
   ----------------------------------------------------------------
 ----------------------------------------------------------------
 to_s. // 스트링으로 바꾸어줌.
 ----------------------------------------------------------------
 instect. // 디버깅할때, 주로 사용함. p 메소드는, 매개
    변수를 inspect한 결과를 출력.
   ----------------------------------------------------------------
   Marshal.dump()
   #oh! 한글 인코딩 확인 같은거 할때도, Mqrshal을 이
    용해서 raw 데이터를 보면 쉽게 볼수있겠군. ㅇㅇ
   ----------------------------------------------------------------
 ----------------------------------------------------------------
 p `date`
 p `pwd`
 `사이에 명령어를 넣으면, 쉘 커맨를 쓸수있음.
 해킹조심!
 ----------------------------------------------------------------
 ----------------------------------------------------------------
 안쓰고 안에 "를 넣으려면, %기호를 이용할 수 있다.
 %!
 ----------------------------------------------------------------
   ----------------------------------------------------------------
    <<"EOS" % 1234
    ...
    ...
   %d
    ...
    EOS

 #? 하나이상은 어떻게넣지? %d,%d
 oh yeah! [1234,123]
 <<-'EOS'


     EOS

  이렇게 - 기호를 넣으면, EOS 앞에 공백이나 탭등을 넣을수 있당.
 ----------------------------------------------------------------
 ----------------------------------------------------------------
 문자 리터럴
 ?1
 ?a
 ?t
 ?x5c
 ----------------------------------------------------------------
 ~77p
 ----------------------------------------------------------------
 str = '<a href="abcdefghijklmn">'


 if /<a href="(.*?)"[ >]/ =~ str
 puts $1 + "로의 링크를 발견"
 end
 ----------------------------------------------------------------
 ----------------------------------------------------------------
 /<a href="(?<url>.*?)"[ >]/ =~ str
 ----------------------------------------------------------------
   ----------------------------------------------------------------
   story = <<EOS
   Solomon Grunday,
   Born on Monday,
   Christened on Tuesday,
   Married on Wednesday.
   EOS

   p story[0],story[1]
   p story[-1]
   p story[8,6] //8부터 6개,
   p story[8...14] //8에서 14까지 ?? ...?
   p story['Monday']
   p story[/w+sday/] // w 영문자+_
 story['Monday']='grace'
//오잉? string이 어떻게 관리되는거지? C언어 같은 경우에는,
배열로 한줄로 관리되는데, 중간값이 바뀌어도 되네.
 테스트 1. 엄청 큰값을 바꿔볼까? 성능테스트.
         2. 관리되는 방식을 소스를 열어서 확인해볼까?
         3. .class로 새로운 클래스가 생기는건지 확인해볼수
  있으려나?.? 스트링의 아이덴티티를 나타내는게 있으려나?
 p story['Monday']
 p story



 ----------------------------------------------------------------
 ----------------------------------------------------------------
 story = story.gsub(/M/,"###")

   story = <<EOS
   Solomon Grunday,
   Born on Monday,
   Christened on Tuesday,
   Married on Wednesday.
   EOS

 story.gsub(/(w+?)day/) { "#{$1}" }
 ----------------------------------------------------------------
 ----------------------------------------------------------------
 str = "gra"
 str << "cen"
 print str
 ----------------------------------------------------------------
 ----------------------------------------------------------------
 print str*3

 "a,bb,ccc,dddd".split(/,s?/) // 정규식에서 s는 공백을 나타낸
  다.
 "string".split(//)

   "abc" == "abc"
   "abc" < "abd"
   "abc" < "acc"
   "a" < "aa"
   "add" <=> "acc"

 ----------------------------------------------------------------
 ----------------------------------------------------------------
 "string".reverse
 "n rstring ".strip
 "string".length
 ----------------------------------------------------------------
 ----------------------------------------------------------------
 "str".each_byte do |byte|
  p byte
 end


 story.each_line do |line|
  print line
 end


 "str".each_char do |c|
  pc
 end



 //흐음 p와 print의 차이가 뭐지? 테스트를 해볼까 멘토님한태 물어볼까 ~.~
 ----------------------------------------------------------------
   ----------------------------------------------------------------
   sprintf("%04d", 3)
   sprintf("%08.4f", Math::PI*10)
   sprintf("Hex=%x, oct=%o", 10, 10)

 "%04d" % 3
 "%08.4f" % Math::PI*10
 "Hex=%x, oct=%o" % [10, 10]



 //86p 에 자세한 포멧스트링들 설명이 나와있음. 시간 남으면 추
  가!
 ----------------------------------------------------------------
 ----------------------------------------------------------------
 :"Anna Terras"
 :"#{$$}"     //$$는 뭐징?
   :"xE3x81x82" //에러남 왜지?
   :'#{ss}'
   :"#{ss}"
   :if
   :some_method_name

 ----------------------------------------------------------------
   ----------------------------------------------------------------
   str1 = "ruby"
   str2 = "ruby"

   str1 == str2
   str1.equal? str2

   symbol1 = :ruby
   symbol2 = :ruby

   symbol1 == symbol2
   symbol1.equal? symbol2

   str1 == symbol1

   so, 심볼을 해시의 키로 사용하기도 함.
   ----------------------------------------------------------------
 ----------------------------------------------------------------
 1.8버전에서는, 여러가지가 다르더라. 우린 1.8 안쓸꺼니까 그냥 알고 넘어가자!


   p "가나다".length

   str = "xe6x97xa5xe6x9cxacxe8xaax9e"

   $KCODE 값을, 'NONE' , 'SJIS', 'EUC', 'UTF8' 등으로 바꿀 수 있음.

   정규표현에서 사용할때는 90p를 봐라!

 인코딩이 다르면, 같은 문자열이라 하더라도 비교 결과가 달라진다.
 (대소관계는 단순히 1바이트씩 비교해보는 알고리즘으로 짜여있음.)


 1.8버전 끝!
 ----------------------------------------------------------------
Ruby 스터디

Weitere ähnliche Inhalte

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Ruby 스터디

  • 2.  ----------------------------------------------------------------  변수값 출력할때, #{a} 이렇게 #{} 사이에 변수명을 넣 어주면 된다.  x**y 는 x의 y승을 말함.  ----------------------------------------------------------------  puts "a #{"값#{  # 주석  "은 #{a}"}"}"  ----------------------------------------------------------------
  • 3.  ----------------------------------------------------------------  to_s. // 스트링으로 바꾸어줌.  ----------------------------------------------------------------  instect. // 디버깅할때, 주로 사용함. p 메소드는, 매개 변수를 inspect한 결과를 출력.  ----------------------------------------------------------------  Marshal.dump()  #oh! 한글 인코딩 확인 같은거 할때도, Mqrshal을 이 용해서 raw 데이터를 보면 쉽게 볼수있겠군. ㅇㅇ  ----------------------------------------------------------------
  • 4.  ----------------------------------------------------------------  p `date`  p `pwd`  `사이에 명령어를 넣으면, 쉘 커맨를 쓸수있음.  해킹조심!  ----------------------------------------------------------------
  • 5.  ----------------------------------------------------------------  안쓰고 안에 "를 넣으려면, %기호를 이용할 수 있다.  %!  ----------------------------------------------------------------
  • 6. ----------------------------------------------------------------  <<"EOS" % 1234  ...  ...  %d  ...  EOS  #? 하나이상은 어떻게넣지? %d,%d  oh yeah! [1234,123]  <<-'EOS'  EOS  이렇게 - 기호를 넣으면, EOS 앞에 공백이나 탭등을 넣을수 있당.  ----------------------------------------------------------------
  • 7.  ----------------------------------------------------------------  문자 리터럴  ?1  ?a  ?t  ?x5c  ----------------------------------------------------------------
  • 8.  ~77p  ----------------------------------------------------------------  str = '<a href="abcdefghijklmn">'  if /<a href="(.*?)"[ >]/ =~ str  puts $1 + "로의 링크를 발견"  end  ----------------------------------------------------------------
  • 9.  ----------------------------------------------------------------  /<a href="(?<url>.*?)"[ >]/ =~ str  ----------------------------------------------------------------
  • 10. ----------------------------------------------------------------  story = <<EOS  Solomon Grunday,  Born on Monday,  Christened on Tuesday,  Married on Wednesday.  EOS  p story[0],story[1]  p story[-1]  p story[8,6] //8부터 6개,  p story[8...14] //8에서 14까지 ?? ...?  p story['Monday']  p story[/w+sday/] // w 영문자+_
  • 11.  story['Monday']='grace' //오잉? string이 어떻게 관리되는거지? C언어 같은 경우에는, 배열로 한줄로 관리되는데, 중간값이 바뀌어도 되네.  테스트 1. 엄청 큰값을 바꿔볼까? 성능테스트.  2. 관리되는 방식을 소스를 열어서 확인해볼까?  3. .class로 새로운 클래스가 생기는건지 확인해볼수 있으려나?.? 스트링의 아이덴티티를 나타내는게 있으려나?  p story['Monday']  p story  ----------------------------------------------------------------
  • 12.  ----------------------------------------------------------------  story = story.gsub(/M/,"###")  story = <<EOS  Solomon Grunday,  Born on Monday,  Christened on Tuesday,  Married on Wednesday.  EOS  story.gsub(/(w+?)day/) { "#{$1}" }  ----------------------------------------------------------------
  • 13.  ----------------------------------------------------------------  str = "gra"  str << "cen"  print str  ----------------------------------------------------------------
  • 14.  ----------------------------------------------------------------  print str*3  "a,bb,ccc,dddd".split(/,s?/) // 정규식에서 s는 공백을 나타낸 다.  "string".split(//)  "abc" == "abc"  "abc" < "abd"  "abc" < "acc"  "a" < "aa"  "add" <=> "acc"  ----------------------------------------------------------------
  • 15.  ----------------------------------------------------------------  "string".reverse  "n rstring ".strip  "string".length  ----------------------------------------------------------------
  • 16.  ----------------------------------------------------------------  "str".each_byte do |byte|  p byte  end  story.each_line do |line|  print line  end  "str".each_char do |c|  pc  end  //흐음 p와 print의 차이가 뭐지? 테스트를 해볼까 멘토님한태 물어볼까 ~.~  ----------------------------------------------------------------
  • 17. ----------------------------------------------------------------  sprintf("%04d", 3)  sprintf("%08.4f", Math::PI*10)  sprintf("Hex=%x, oct=%o", 10, 10)  "%04d" % 3  "%08.4f" % Math::PI*10  "Hex=%x, oct=%o" % [10, 10]  //86p 에 자세한 포멧스트링들 설명이 나와있음. 시간 남으면 추 가!  ----------------------------------------------------------------
  • 18.  ----------------------------------------------------------------  :"Anna Terras"  :"#{$$}" //$$는 뭐징?  :"xE3x81x82" //에러남 왜지?  :'#{ss}'  :"#{ss}"  :if  :some_method_name  ----------------------------------------------------------------
  • 19. ----------------------------------------------------------------  str1 = "ruby"  str2 = "ruby"  str1 == str2  str1.equal? str2  symbol1 = :ruby  symbol2 = :ruby  symbol1 == symbol2  symbol1.equal? symbol2  str1 == symbol1  so, 심볼을 해시의 키로 사용하기도 함.  ----------------------------------------------------------------
  • 20.  ----------------------------------------------------------------  1.8버전에서는, 여러가지가 다르더라. 우린 1.8 안쓸꺼니까 그냥 알고 넘어가자!  p "가나다".length  str = "xe6x97xa5xe6x9cxacxe8xaax9e"  $KCODE 값을, 'NONE' , 'SJIS', 'EUC', 'UTF8' 등으로 바꿀 수 있음.  정규표현에서 사용할때는 90p를 봐라!  인코딩이 다르면, 같은 문자열이라 하더라도 비교 결과가 달라진다.  (대소관계는 단순히 1바이트씩 비교해보는 알고리즘으로 짜여있음.)  1.8버전 끝!  ----------------------------------------------------------------