Python 개발자 및 미니 물고기 앱으로 Ruby 선택

10446 단어 rubypythoncodenewbie
이것은 Python 개발자로서 Ruby Fast 선택의 연속입니다. 다시 말하지만, 수학이 없고 진절머리 나는 이름을 최소화한 예를 기대하세요.


여러 방법으로 메시지를 보내시겠습니까?



이것이 Python에서 할 수 있는 일인지 확실하지 않지만 Ruby에서는 할 수 있습니다. 아래 예feed "dogs" if meal_time?(5)에서 한 번에 2개의 메서드를 실행합니다.
?의 이 mealt_time?도 나에게 새로운 것이며 Python에서는 본 적이 없습니다. Python에서는 is_it_meal_time 와 같은 변수를 수행했을 것입니다.

#ruby
def meal_time? time_hrs
  if time_hrs >=5
    puts "cat is singing song of his people, guess it's food time"
    true
  else
    puts "tell cat to try again in an hour"
    false
  end
end

def feed pet
    puts "put food in #{pet} bowl\n"

end

feed "cats" if meal_time?(4)
feed "dogs" if meal_time?(5)
feed "cats" if meal_time?(18)
feed "dogs" if meal_time?(18)

클래스



클래스는 Python에서 Ruby까지 약간 다르게 보이지만 기본적으로 동일한 개념인 것처럼 보입니다. attr_accessor@는 나에게 새로운 부품입니다.

지금까지 리뷰했던 것들을 모아놓은 미니피쉬 앱



내 어항에 있는 것들의 수위를 추적하기 위한 미니 앱을 만들려고 했으므로 여기 있습니다.

# ruby
class Water_Level
  attr_accessor :time, :ph, :ammonia, :nitrites, :nitrates, :temp

  def initialize(ph, ammonia, nitrites, nitrates, temp)
    @time = Time.now
    @ph = ph
    @ammonia = ammonia
    @nitrites = nitrites
    @nitrates = nitrates
    @temp = temp
  end
end

Water_Level.new.time

class Levelizer
  def initialize(title)
    @title  = title
    @levels = [] 
  end

  def add_a_level(ph, ammonia, nitrites, nitrates, temp)
    # The << means add to the end of the array
    @levels << Level.new(ph, ammonia, nitrites, nitrates, temp)
  end

  def show_timeline
    puts "Fishify: #{@title} has tracked #{@levels.count} Levels"

    @levels.sort_by { |t|
      t.time
    }.reverse.each { |t|
      puts "#{t.ph} #{t.ammonia} #{t.nitrites} #{t.nitrates} #{t.temp} #{t.time}"
    }
  end
end

myapp = Levelizer.new "Vicki's Betta Tank"

myapp.add_a_level 7.4, 0, 0, 0, 78.2
myapp.add_a_level 7.4, 0, 0, 0, 72.3
myapp.add_a_level 7.2, 0, 0, 0, 79.1

myapp.show_timeline

"""
# output
Fishify: Vicki's Betta Tank has tracked 3 Levels
7.2 0 0 0 79.1 Thu Nov 19 2020 14:04:59 GMT-0500 (Eastern Standard Time)
7.4 0 0 0 72.3 Thu Nov 19 2020 14:04:59 GMT-0500 (Eastern Standard Time)
7.4 0 0 0 78.2 Thu Nov 19 2020 14:04:59 GMT-0500 (Eastern Standard Time)
"""




자신에게 알림: 무급 노동이 허용된다고 생각하는 곳에서 일하지 마십시오.






비키 랑거


@vicki_langer






아무래도 면접 때 회사에 물어볼 질문 목록에 추가해야 할 것 같네요. - 무급 인턴이나 펠로우가 있나요?


오후 18:19 - 2020년 11월 18일











이 시리즈의 첫 번째 게시물을 놓쳤다면 잘 읽었고 고양이가 있다고 들었습니다.


좋은 웹페이지 즐겨찾기