Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RString utf8 fixes #101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add RString::new_ascii
  • Loading branch information
Palladinium committed Jun 6, 2019
commit 722c42bed08b5b7abb87be7fbc20779697c567f6
25 changes: 25 additions & 0 deletions src/class/string.rs
Original file line number Diff line number Diff line change
@@ -62,6 +62,31 @@ impl RString {
Self::from(string::new_utf8(string))
}

/// Creates a new instance of Ruby `String` containing given `string`.
/// This method forces the string's encoding to ASCII-8bit.
///
/// # Examples
///
/// ```
/// use ruru::{RString, VM};
/// # VM::init();
///
/// let string = RString::new_ascii("Hello, World!");
///
/// assert_eq!(string.to_str(), "Hello, World!");
/// ```
///
/// Ruby:
///
/// ```ruby
/// str = 'Hello, World!'
///
/// str == 'Hello, World!'
/// ```
pub fn new_ascii(string: &str) -> Self {
Self::from(string::new(string))
}

/// Retrieves underlying Rust `String` from Ruby `String` object.
///
/// # Examples