Javascript 文字列の整形

index.html

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My JavaScript</title>
</head>
<body>
  <script src="main.js"></script>
</body>
</html>

main.js

'use strict';

{
  const string = prompt('Name?');
  //if(string.toLowerCase() === 'taro'){
  if(string.toUpperCase().trim() === 'TARO'){
    console.log('Corrent!');
  }else{
    console.log('Wrong!');
  }
}

ruby メソッドをオーバーライド

class Score
  def initialize(subject, score)
    @subject = subject
    @score = score
  end

  def get_info
    "#{@subject}/#{@score} -> #{get_result}"
  end

  private

  def get_result
    @score >= 80 ? "Pass" : "Fail"
  end
end

class MathScore < Score
  def initialize(score)
    super("Math", score)
  end

  private 

  # ovierride
  def get_result
  @score >= 50 ? "Pass" : "Fail"
  end
end

class EnglishScore < Score
  def initialize(score)
    super("English", score)
  end
end

class User
  def initialize(name, score)
    @name = name
    @score = score
  end

  def get_info
    "Name: #{@name}, Score: #{@score.get_info}"
  end
end

user1 = User.new("Taro", MathScore.new(70))
user2 = User.new("Jiro", EnglishScore.new(90))
puts user1.get_info
puts user2.get_info

ruby 子クラス

class Score
  def initialize(subject, score)
    @subject = subject
    @score = score
  end

  def get_info
    "#{@subject}/#{@score} -> #{get_result}"
  end

  private

  def get_result
    @score >=80 ? "Pass" : "Fail"
  end
end

class MathScore < Score
  def initialize(score)
  super("Math", score)
  end
end

class EnglishScore < Score
 def initialize(score)
  super("Math", score)
  end
end

class User
  def initialize(name, score)
    @name = name
    @score = score
  end

  def get_info
    "Name: #{@name}, Score: #{@score.get_info}"
  end
end

user1 = User.new("Taro", MathScore.new(70))
user2 = User.new("Jiro", EnglishScore.new(90))
puts user1.get_info
puts user2.get_info

C# string型とchar型

using System;

class string01
{
    public static void Main()
    {
        char[] chararray = new char[3];
        chararray[0] = 'a';
        chararray[1] = 'b';
        chararray[2] = 'c';

        string str;
        str = new string(chararray);
        Console.WriteLine(str);

        char[] title = { '魔', '王', 'と', '勇', '者'};
        string strTitle = new string(title);
        Console.WriteLine(strTitle);


        string strx = "魔王と勇者の伝説";
        int n = strx.Length;
        Console.WriteLine("「{0}」の文字数は{1}です", strx, n);

        char c = strx[1];
        Console.WriteLine("「{0}」の2番目の文字は「{1}」です", strx, c);


    }
}

python 簡単な会話モデルの構築

from nltk.chat.util import Chat, reflections

pairs = [
[‘こんにちは’, [‘こんにちは!’, ‘どうもこんにちは!’]],
[‘元気ですか?’, [‘はい、元気です!’, ‘お尋ねいただきありがとうございます。’]],
[‘名前は何ですか?’, [‘私はチャットボットです。’, ‘私の名前はチャットボットです。’]],
[‘さようなら’, [‘さようなら!またね。’, ‘良い一日を!’]],
]

chatbot = Chat(pairs, reflections)

def chatbot_response(user_input):
return chatbot.respond(user_input)

ユーザーとの対話

while True:
user_input = input(“あなた: “)
response = chatbot_response(user_input)
print(“チャットボット:”, response)

C# 配列

using System;

class array01
{
    public static void Main()
    {
        int[] Weapon = new int[3];
        Weapon[0] = 10;
        Weapon[1] = 20;
        Weapon[2] = 30;
        // 宣言と同時に初期化
        int[] myarray2 = new int[3] { 10, 20, 30 };

        // 要素数を省略することも可能
        int[] myarray3 = new int[] { 10, 20, 30 };

        //別な方法
        int[] myarray4;
        myarray4 = new int[] { 10, 20, 30 };
    }
}

ruby メソッドを実装

class Score
  def initialize(subject, score)
    @subject = subject
    @score = score
  end

  def get_info
    "#{@subject}/#{@score}"
  end
end

class User
  def initialize(name, score)
    @name = name
    @score = score
  end

  def get_info
    "Name: #{@name}, Score: #{@score.get_info}"
  end
end

user1 = User.new("Taro", Score.new("Math", 70))
user2 = User.new("Jiro", Score.new("English", 90))
puts user1.get_info
puts user2.get_info

Ruby RSS

require 'rss'
require 'open-uri'

# RSSフィードのURL
rss_url = 'http://2ch-ranking.net/rss/livemarket1.rdf'

# RSSフィードを取得してパース
rss_content = URI.open(rss_url).read
rss = RSS::Parser.parse(rss_content)

# フィードのタイトルと記事を出力
puts "フィードのタイトル: #{rss.channel.title}"
puts "-----"

rss.items.each do |item|
  puts "タイトル: #{item.title}"
  puts "リンク: #{item.link}"
  puts "概要: #{item.description}"
  puts "-----"
end

ruby クラスメソッド

class User
  @@count = 0

  def initialize(name, score)
    @name = name
    @score = score
    @@count += 1
  end

  def get_info
    "Name: #{@name}, Score: #{@score}"
  end

  def self.get_info
    "Count: #{@@count}"
  end
end

# count = 0
user1 = User.new("Taro", 70)
# count += 1
user2 = User.new("Jiro", 90)
# count += 1
# puts count
puts User.get_info